Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6547744
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Oracle

2010-05-25 20:22:25

分段提交删除大批量数据

例子1:

declare
i integer;
begin
loop
execute immediate 'delete from tb_name f_a=xxx and f_b=yyy and romnum<5000';
commit;
select count(*) into i from tb_name f_a=xxx and f_b=yyy;
exit when i=0;
end loop;
end;

例子2:

set serveroutput on
Declare
 rcode
integer;
 
begin

 loop
 
--每10000次将表a删除10000条记录
 delete from a
 
where exists (select usercode from b where a.usercode =
b.usercode)
 
and rownum < 10000
;
--每10000条提交一次

 commit;
 
exit when sql%rowcount = 0
;
 
end
loop;
 rcode :
= 1
;
 
--delete操作完成后,rcode值为1

 dbms_output.put_line('结果是:'||to_char(rcode));
 exception
 
when others then

 
rollback;
 rcode :
= 0
;
 
--delete操作失败后,rcode值为0

 dbms_output.put_line('结果是:'||to_char(rcode));
 
end;

例子3:

分批写入数据

create or replace procedure sp_insert_data
as
begin
for i in 1..1000000 loop
insert into tb_hxl_test
values(i,to_char(i)||chr(i));
if mod(i,100000)= 0 then
insert into tb_hxl_log values (i,'commit');
commit;
end if;
end loop;
commit;
exception
when NO_Data_Found then dbms_output.put_line('no data found');
when others then rollback;
end sp_insert_data;

阅读(7899) | 评论(0) | 转发(1) |
0

上一篇:没有了

下一篇:awk用法小结

给主人留下些什么吧!~~