oracle分批次提交 假如test表有a,b,c三列;
如果test_new的表结构和test的表结构一模一样,能用下面的方法做 demo1
declare
cursor c is
select * from test;
type c_type is table of c%rowtype;
v_type c_type;
begin
open c;
loop
fetch c bulk collect into v_type limit 50000;
forall i in 1 .. v_type.count
insert into test_new values v_type (i);
commit;
exit when c%notfound;
end loop;
close c;
commit;
end;
如果test_new的表结构和test的表结构不一样,只能把每一列都定义一个类型,才能插入 demo2
type a_type is table of test.a%type;
……
type c_type is table of test.c%type;
a_type_ref a_type;
……
c_type_ref c_type;
然后
loop
fetch c bulk collect into a_type_ref,b_type_ref,c_type_ref limit 50000;
forall i in 1 .. a_type.count
insert into test_new(a,b,c) values v_type (a_type_ref,a_type_ref,a_type_ref);
commit;
exit when c%notfound;
end loop;