buck into 练习

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;

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/46907/viewspace-917144/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/46907/viewspace-917144/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值