declare
cursor c is select * from hxz_01;
l_rec hxz_01%rowtype;
begin
open c;
loop
fetch c into l_rec;
exit when c%notfound;
dbms_output.put_line(l_rec.a);
end loop;
close c;
end;
declare
cursor c is select * from hxz_01;
TYPE fetch_array IS TABLE OF hxz_01%ROWTYPE;
l_rec fetch_array;
begin
open c;
fetch c bulk collect into l_rec;
for i in 1..l_rec.count loop
dbms_output.put_line(l_rec(i).a);
end loop;
close c;
end;
----------------------------------------------------------
--Example One
declare
cursor c is select * from hxz_01;
type type_t is table of hxz_01%rowtype;
l_rec type_t;
begin
open c;
fetch c bulk collect into l_rec;
forall i in 1..l_rec.count
insert into hxz_02 values l_rec(i);
commit;
close c;
end;
--Example Two
declare
cursor c is select * from hxz_01;
type type_t is table of hxz_01%rowtype;
l_rec type_t;
begin
open c;
fetch c bulk collect into l_rec;
for i in l_rec.first..l_rec.last loop
dbms_output.put_line(l_rec(i).a||l_rec(i).b);
end loop;
end;
--Example Three
declare
cursor c is select * from hxz_01;
l_rec hxz_01%rowtype;
begin
open c;
loop
fetch c into l_rec;
exit when c%notfound;
dbms_output.put_line(l_rec.a||l_rec.b);
end loop;
end;
-----------------------------------------------------
--Example Four
TYPE myarray IS TABLE OF servers2.srvr_id%TYPE
INDEX BY BINARY_INTEGER;
d_array myarray;
declare
type type_t is table of hxz_01.a%type index by binary_integer;
l_rec type_t;
begin
l_rec(1) :='1';
l_rec(2) :='2';
l_rec(3) :='3';
forall i in l_rec.first..l_rec.last
delete hxz_02 where a = l_rec(i);
for i in l_rec.first..l_rec.last loop
dbms_output.put_line(sql%bulk_rowcount(i));
end loop;
/* commit;*/
end;
------------------------------------------------------------------
declare
cursor c is select * from hxz_01;
type type_t is table of hxz_01%rowtype;
l_rec type_t;
begin
select * bulk collect into l_rec from hxz_01;
for i in 1..l_rec.last
loop
dbms_output.put_line(l_rec(i).a);
if l_rec(i).a = '3' then
dbms_output.put_line(i);
dbms_output.put_line(l_rec(i).b);
l_rec.delete(i);
end if;
end loop;
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/46907/viewspace-917144/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/46907/viewspace-917144/