Home >Database >Mysql Tutorial >Oracle中大批量删除数据的方法

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

WBOY
WBOYOriginal
2016-06-07 18:04:211014browse

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

写一个循环删除的过程。
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 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 PL/SQL procedure successfully completed.
Elapsed: 00:00:18.54
方法虽好,但我应用在一个亿级数据库时还是觉得慢得不行。就算删一点点数据也觉得好象挺慢的。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn