大表数据插入批量提交
2015-12-01 14:41
459 查看
对大表进行插入时,数据非常多,会把undo表空间撑爆,导致插入不成功,可以使用批量提交进行插入,及时释放回滚段。
declare
--定义cursor把数据全部读入内存中
cursor cur is
select nsrzhdah, sfzjlx_dm, sfzjhm, xm, nsrsbh,
zlsfqq, lydm, yxbz, bdbz, hcode,
fkid , fxbz, zrrlx_dm , xybz , lrrq ,
lrr_dm, xgrq , xgr_dm , nsrswjg_dm,wspzxh ,
ywxh , bdlx_dm , czlx_dm , sjlyxt , sjjzrq ,
sjscrq , sjbgbz , sjtjrq , sjgsdq
from j1_g3_zbq.INFT02_JBXX_ZRR;
--自定义集合类型
type rec is table of cur%rowtype;
recs rec;
begin
execute immediate 'alter table j1_ldm.ldmt02_jbxx_zrr nologging';
open cur;
while (true) loop
fetch cur bulk collect
into recs limit 10000;--10000行执行一次游标读取操作
--把数据逐条插入
forall i in 1 .. recs.count
insert into j1_ldm.ldmt02_jbxx_zrr values recs (i);
commit;
exit when cur%notfound;
end loop;
close cur;
execute immediate 'alter table j1_ldm.ldmt02_jbxx_zrr logging';
end;
/
declare
2 cursor c_t is select * from t;
3 type typ_t is table of c_t%rowtype
4 index by binary_integer;
5 v_type_t typ_t;
6 v_row pls_integer;
7 begin
8 open c_t;
9 loop
10 fetch c_t bulk collect into v_type_t
11 limit 100;
12 exit when v_type_t.count = 0;
13 dbms_output.put_line(v_type_t.count);
14 v_row :=v_type_t.first;
15 while(v_row is not null)
16 loop
17 -- dbms_output.put_line(v_type_t(v_row).empno);
18 null;
19 v_row :=v_type_t.next(v_row);
20 end loop;
21 end loop;
22 close c_t;
23 end;
24 /
declare
--定义cursor把数据全部读入内存中
cursor cur is
select nsrzhdah, sfzjlx_dm, sfzjhm, xm, nsrsbh,
zlsfqq, lydm, yxbz, bdbz, hcode,
fkid , fxbz, zrrlx_dm , xybz , lrrq ,
lrr_dm, xgrq , xgr_dm , nsrswjg_dm,wspzxh ,
ywxh , bdlx_dm , czlx_dm , sjlyxt , sjjzrq ,
sjscrq , sjbgbz , sjtjrq , sjgsdq
from j1_g3_zbq.INFT02_JBXX_ZRR;
--自定义集合类型
type rec is table of cur%rowtype;
recs rec;
begin
execute immediate 'alter table j1_ldm.ldmt02_jbxx_zrr nologging';
open cur;
while (true) loop
fetch cur bulk collect
into recs limit 10000;--10000行执行一次游标读取操作
--把数据逐条插入
forall i in 1 .. recs.count
insert into j1_ldm.ldmt02_jbxx_zrr values recs (i);
commit;
exit when cur%notfound;
end loop;
close cur;
execute immediate 'alter table j1_ldm.ldmt02_jbxx_zrr logging';
end;
/
open xxxx for select .....; 打开游标 loop fetch xxxx bulk collect into v1,v2,v3..... limit 1000; --限制每次取1000行 n_count := v1.count; --获取本次FETCH得到的行数 exit when n_count = 0;--等于0则退出循环 forall i in v1.first .. v1.last insert into ... values (v1(i),v2(i),.....); --批量插入 commit; 一次提交 end loop; close XXXX; --关闭游标 |
2 cursor c_t is select * from t;
3 type typ_t is table of c_t%rowtype
4 index by binary_integer;
5 v_type_t typ_t;
6 v_row pls_integer;
7 begin
8 open c_t;
9 loop
10 fetch c_t bulk collect into v_type_t
11 limit 100;
12 exit when v_type_t.count = 0;
13 dbms_output.put_line(v_type_t.count);
14 v_row :=v_type_t.first;
15 while(v_row is not null)
16 loop
17 -- dbms_output.put_line(v_type_t(v_row).empno);
18 null;
19 v_row :=v_type_t.next(v_row);
20 end loop;
21 end loop;
22 close c_t;
23 end;
24 /
相关文章推荐
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- Oracle Containers for J2EE远程安全漏洞(CVE-2014-0413)
- Oracle 10g R2不能使用EM的问题
- 表空间操作
- PreparedStatement中in子句的处理
- VMware下RedHat4.8_64位安装Oracle 10g RAC--简略脚本
- oracle sql日期比较
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- OS block size和Oracle block size,查找OS Blocksize的方法
- oracle中创建数据库和表空间的几点总结
- 数据库自动备份脚本
- oracle的nvl函数的使用介绍
- 解决oracle用户连接失败的解决方法
- oracle的一些tips技巧
- Oracle 下的开发日积月累
- Oracle存储过程之数据库中获取数据实例
- Windows下ORACLE 10g完全卸载的方法分析
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ORACLE LATERAL-SQL-INJECTION 个人见解