假如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;
问题在这,如果test_new列比较多,并且和test表结构还不一样,还想分批提交,
怎么搞比较简单像demo1那么简单的,而不像demo2那样定义那么多类型呢?
------最佳解决方案--------------------
我来学习一下,增长见识
------其他解决方案--------------------
cursor c is
select 列1,列2,。。列n from test;
--你在游标里拼成跟test_new的结构一样就行了,然后不用变
------其他解决方案--------------------
就用test的表的ROWTYPE来接收NEW_TEST查询的数据,再直接插入不可以吗?
------其他解决方案--------------------
你自定义一个table类型的游标不行吗?
------其他解决方案--------------------
这位老哥,不好意思前段时间忙的很,没空回复。
你那种方法我早就试过,不可以的。
------其他解决方案--------------------
不行,不信你试试呢。