Comparing collection against cursor [message #292428] |
Tue, 08 January 2008 22:58 |
shahnazurs
Messages: 240 Registered: June 2005 Location: India
|
Senior Member |
|
|
Hi,
I have checked the following two codes, both are giving the same result. Please tell me which method is optimized one.
Code 1:-
--------
declare
type nttype is table of emp%rowtype;
nt nttype;
begin
select * bulk collect into nt
from emp;
for i in nt.first..nt.last
loop
if nt(i).sal>1500 then
dbms_output.put_line(nt(i).empno||','||nt(i).ename||','||nt(i).sal);
end if;
end loop;
exception
when others then
dbms_output.put_line('Error');
end;
Code 2:-
--------
declare
cursor c1
is select * from emp;
c1rec c1%rowtype;
begin
open c1;
loop
fetch c1 into c1rec;
exit when c1%notfound;
if c1rec.sal>1500 then
dbms_output.put_line(c1rec.empno||','||c1rec.ename||','||c1rec.sal);
end if;
end loop;
close c1;
exception
when others then
dbms_output.put_line('Error');
end;
Thanks.
|
|
|
|
|