当前位置: 移动技术网 > IT编程>数据库>Oracle > Oracle中大批量删除数据的方法

Oracle中大批量删除数据的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

魅丽莱,嘻哈猴头像,安琪 流泪的眼

写一个循环删除的过程。
create or replace procedure delbigtab(p_tablename in varchar2,p_condition in varchar2,p_count in varchar2) 
as
pragma autonomous_transaction;
n_delete number:=0;
begin
 while 1=1 loop
execute immediate
'delete from '||p_tablename||' where '||p_condition||' and rownum <= :10000'
using p_count;
if sql%notfound then
exit;
else
n_delete:=n_delete + sql%rowcount;
end if;
commit;
end loop;
commit;
dbms_output.put_line('finished!');
dbms_output.put_line('totally '||to_char(n_delete)||' records deleted!');
end delbigtab; 
调用:
sql> set timing on
sql> exec delbigtab('hs_dlf_downlog_history','numdlflogguid < 11100000','10000');
pl/sql procedure successfully completed.
elapsed: 00:00:18.54
方法虽好,但我应用在一个亿级数据库时还是觉得慢得不行。就算删一点点数据也觉得好象挺慢的。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网