假如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那样定义那么多类型呢?
如果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那样定义那么多类型呢?
解决方案 »
- 使用ALTER TABLE .. MOVE TABLESPCE ..后如何收缩原表空间
- ora错误码IMP-00003/ORA-00942/IMP-00008
- 表中有关键字段 怎样写SQL 语句????
- oracle存储过程中的类型转换
- 关于ORACLE和MS SQL Server数据交换的问题
- oracle10g 如何创建数据库?
- oracle条件部分用字段的部分内容进行比较问题!
- 两个时间怎么比较相差多少年或多少月或多少日
- oracle安装时listener的问题,高手请指教!正好8月15了,回答个问题,祝你中秋快乐!
- in 在存储过程中怎么会出现这种情况,请教!
- 求助大神:有没有办法将一张表中的数据记录转换成一定格式的TXT文本文件
- PL/SQL存储过程的问题!!!!!!!!!!在线等!!!!!!!!!!!!
cursor c is
select 列1,列2,。。列n from test;
--你在游标里拼成跟test_new的结构一样就行了,然后不用变