分段提交删除大批量数据

分段提交删除大批量数据[@more@]

例子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
None.gifDeclare
None.gif rcode integer;
None.gifbegin
None.gif loop
None.gif--每None.gif次将表a删除10000条记录
None.gif delete from a
None.gifwhere exists (select usercode from b where a.usercode = b.usercode)
None.gifand rownum < 10000;
None.gif--每10000条提交一次
None.gif commit;
None.gifexit when sql%rowcount = 0;
None.gifend loop;
None.gif rcode := 1;
None.gif--delete操作完成后,rcode值为1
None.gif dbms_output.put_line('结果是:'||to_char(rcode));
None.gif exception
None.gifwhen others then
None.gifrollback;
None.gif rcode := 0;
None.gif--delete操作失败后,rcode值为0
None.gif dbms_output.put_line('结果是:'||to_char(rcode));
None.gifend;

例子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;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/77311/viewspace-1025183/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/77311/viewspace-1025183/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值