ITPub博客

首页 > Linux操作系统 > Linux操作系统 > forall and bulk collect

forall and bulk collect

原创 Linux操作系统 作者:hxhy 时间:2019-04-16 10:54:04 0 删除 编辑
forall 和bulk collect的用法

create table test_table
(id int,c2 varchar2(20),c3 varchar2(20),c4 varchar2(20) );

declare
begin
for i in 1..10000 loop
insert into test_table values(i,lpad(i,20,'x'),lpad(i,20,'y'),lpad(i,20,'z'));
end loop;
commit;
end;
/

delete from test_table ;
commit;

declare
type test_type is table of test_table%rowtype;
v_test test_type :=test_type();
begin
v_test.extend(10000);
for i in 1..10000 loop
v_test(i).id := i;
v_test(i).c2 := lpad(i,20,'x');
v_test(i).c3 := lpad(i,20,'y');
v_test(i).c4 := lpad(i,20,'z');
end loop;
forall j in v_test.first..v_test.last
insert into test_table values v_test(j);
commit;
end;
/

create table test_copy_table
(id int,c2 varchar2(20),c3 varchar2(20),c4 varchar2(20) );

begin
insert into test_copy_table select * from test_table;
commit;
end;
/
delete from test_copy_table;
commit;


declare
type test_type is table of test_copy_table%rowtype;
v_test test_type;
begin
select * bulk collect into v_test from test_table;
forall i in v_test.first .. v_test.last
insert into test_copy_table values v_test(i);
commit;
end;
/

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

请登录后发表评论 登录
全部评论

注册时间:2003-06-28

  • 博文量
    27
  • 访问量
    25525