declare
cursor c1 is select level m, level*10 n from dual connect by level < 3;
n number;
m number;
begin
-- Open explicit cursor fetch record one by one exit after exhausting close cursor
open c1;
loop
fetch c1 into m,n;
dbms_output.put_line('m'||m|| ' n'||n);
exit when c1%notfound;
end loop;
close c1;
/* No need to explicitly open the cursor fetch will not work as c2 is rowtype ,so here is an implicit copy from cursor initial record pointer to c2 ,,Cursor will be closed automatically once iteration exhausts all the records , cursor record values can be used via c2 record attributes . */
for c2 in c1 loop
m:= c2.m; n:= c2.n;
dbms_output.put_line('for m'||m|| ' n'||n);
end loop;
end;
Comments
Post a Comment