Wednesday, 25 February 2015

Cursor using the for loop
Example:
declare
p number(6);
cursor c is
select * from emp for update;
begin
for i in c
loop
select avg(sal) into p from emp where empno=i.empno group by deptno;
dbms_output.put_line(i.empno);
end loop;
end;

WHILE LOOP:
declare
cursor c is
select * from emp;
x emp%rowtype;
begin
open c;
fetch c into x;
while (c%found) loop
dbms_output.put_line(x.ename);
fetch c into x;
end loop;
end;


so, better to use the for loop

No comments:

Post a Comment