0% found this document useful (0 votes)
10 views6 pages

SQL Cursor Operations and Error Handling

The document outlines a series of SQL commands executed to create a table named 'cursors_01' and insert employee records into it. It demonstrates inserting data for employees, updating their salaries using a cursor, and displaying the updated records. The final output shows the updated salaries for the employees 'abi' and 'kavi'.

Uploaded by

b.comcasvcas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

SQL Cursor Operations and Error Handling

The document outlines a series of SQL commands executed to create a table named 'cursors_01' and insert employee records into it. It demonstrates inserting data for employees, updating their salaries using a cursor, and displaying the updated records. The final output shows the updated salaries for the employees 'abi' and 'kavi'.

Uploaded by

b.comcasvcas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SQL>

connect

Enter user-
name:
system

Enter
password:

Connected.

SQL> insert
into
cursors_01
values(&e_n
o,'&name',&
salary);

Enter value
for e_no: 01

Enter value
for name:
alamu

Enter value
for salary:
10000

old 1:
insert into
cursors_01
values(&e_n
o,'&name',&
salary)

new 1:
insert into
cursors_01
values(01,'al
amu',10000)

insert into
cursors_01
values(01,'al
amu',10000)

ERROR at
line 1:

ORA-00942:
table or
view does
not exist
SQL> create
table
cursors_01 (

2 e_no
number(5),
e_name
varchar2(15
), salary
number(10)

3 );

Table
created.

SQL> insert
into
cursors_01
values(&e_n
o,'&name',&
salary);

Enter value
for e_no: 01

Enter value
for name:
abi

Enter value
for salary:
10000

old 1:
insert into
cursors_01
values(&e_n
o,'&name',&
salary)

new 1:
insert into
cursors_01
values(01,'a
bi',10000)

1 row
created.

SQL> /
Enter value
for e_no: 02

Enter value
for name:
kavi

Enter value
for salary:
20000

old 1:
insert into
cursors_01
values(&e_n
o,'&name',&
salary)

new 1:
insert into
cursors_01
values(02,'k
avi',20000)

1 row
created.

SQL> desc
cursors_01;

Name
Null? Type

----------------
----------------
---------
--------
----------------
------------

E_NO
NUMBER(5)

E_NAME
VARCHAR2(
15)

SALARY
NUMBER(10
)
SQL> select
* from
cursors_01;

E_NO
E_NAME
SALARY

----------
---------------
----------

1 abi
10000

2 kavi
20000

SQL>
commit;

Commit
complete.

SQL>
declare

2 cursor
emp_cur is
select *
from
cursors_01
where
salary>2000
; emp_no
cursors_01.
e_no %
type;

3
emp_name
cursors_01.
e_name %
type;
emp_sal
cursors_01.s
alary %
type; begin

4 open
emp_cur;
loop
5 fetch
emp_cur
into
emp_no,em
p_name,em
p_sal; exit
when
emp_cur %
notfound;

6 update
cursors_01
set
salary=salar
y+100
where
e_no=emp_
no; end
loop;

7 commit;

8 close
emp_cur;
end;

9 /

PL/SQL
procedure
successfully
completed.

SQL>

SQL> set
serveroutpu
t on;

SQL> select
* from
cursors_01;

E_NO
E_NAME
SALARY

----------
---------------
----------

1 abi
10100
2 kavi
20100

SQL>
commit;

Commit
complete.

You might also like