读书人

oracle分批次交付

发布时间: 2012-12-14 10:33:07 作者: rapoo

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;

问题在这,如果test_new列比较多,并且和test表结构还不一样,还想分批提交,
怎么搞比较简单像demo1那么简单的,而不像demo2那样定义那么多类型呢?
[最优解释]
我来学习一下,增长见识
[其他解释]


cursor c is
select 列1,列2,。。列n from test;
--你在游标里拼成跟test_new的结构一样就行了,然后不用变

[其他解释]
就用test的表的ROWTYPE来接收NEW_TEST查询的数据,再直接插入不可以吗?
[其他解释]
你自定义一个table类型的游标不行吗?
[其他解释]
引用:
SQL code?1234cursor c is select 列1,列2,。。列n from test;--你在游标里拼成跟test_new的结构一样就行了,然后不用变


这位老哥,不好意思前段时间忙的很,没空回复。

你那种方法我早就试过,不可以的。


[其他解释]
引用:
就用test的表的ROWTYPE来接收NEW_TEST查询的数据,再直接插入不可以吗?


不行,不信你试试呢。

读书人网 >oracle

热点推荐