0% found this document useful (0 votes)
12 views

Ass 3

This document contains 3 examples of PL/SQL cursors. The first example declares a cursor to select all records from an employee table and outputs the results. The second example declares a cursor to select a specific record based on an employee ID, then updates the salary field. The third example declares a cursor to select records between lower and upper salary limits provided.

Uploaded by

Fatosh Lois
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Ass 3

This document contains 3 examples of PL/SQL cursors. The first example declares a cursor to select all records from an employee table and outputs the results. The second example declares a cursor to select a specific record based on an employee ID, then updates the salary field. The third example declares a cursor to select records between lower and upper salary limits provided.

Uploaded by

Fatosh Lois
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

declare

cursor cur_emp is select * from employee1;

emp_rec employee1 %rowtype;

begin

open cur_emp;

if cur_emp %isopen then

loop

fetch cur_emp into emp_rec;

exit when cur_emp %notfound;

dbms_output.put_line(emp_rec.emp_id||' '||emp_rec.emp_name||' '

||emp_rec.DEP_NAME);

end loop;

close cur_emp;

else

dbms_output.put_line('Cursor is closed ');

end if;

end;

=================================================================================
=======

2. DECLARE

CURSOR CUR_EMP(E_ID EMPLOYEE1.EMP_ID %TYPE)IS SELECT * FROM EMPLOYEE1 WHERE


EMP_ID=E_ID;

E_ID EMPLOYEE1.EMP_ID%TYPE:=&E_ID;

emp_rec employee1 %rowtype;

BEGIN

open cur_emp(e_id);

if cur_emp %isopen then


loop

fetch cur_emp into emp_rec;

exit when cur_emp %notfound;

update employee1 set salary =salary+(salary*0.5)WHERE EMP_ID=E_ID;

dbms_output.put_line('Salary Updated');

end loop;

close cur_emp;

else

dbms_output.put_line('Cursor is closed ');

end if;

end;

===================

3. DECLARE

CURSOR CUR_EMP(l_lt EMPLOYEE1.salary %TYPE,u_lt EMPLOYEE1.salary %TYPE)IS


SELECT * FROM EMPLOYEE1 WHERE salary between l_lt and u_lt;

l_lt EMPLOYEE1.salary %TYPE:=&l_lt;

u_lt EMPLOYEE1.salary %TYPE


=======================================================================

:=&u_lt;

BEGIN

for emp_rec in cur_emp(l_lt,u_lt)

loop

dbms_output.put_line(emp_rec.emp_name||' '||emp_rec.salary);

end loop;

end;

You might also like