写一个循环删除的过程。
createorreplaceproceduredelBigTab(p_TableNameinvarchar2,p_Conditioninvarchar2,p_Countinvarchar2)
as
pragmaautonomous_transaction;
n_deletenumber:=0;
begin
while1=1loop
EXECUTEIMMEDIATE
'deletefrom'||p_TableName||'where'||p_Condition||'andrownum<=:10000'
USINGp_Count;
ifSQL%NOTFOUNDthen
exit;
else
n_delete:=n_delete+SQL%ROWCOUNT;
endif;
commit;
endloop;
commit;
DBMS_OUTPUT.PUT_LINE('Finished!');
DBMS_OUTPUT.PUT_LINE('Totally'||to_char(n_delete)||'recordsdeleted!');
enddelBigTab;
调用:
SQL>settimingon
SQL>execdelBigTab('HS_DLF_DOWNLOG_HISTORY','NUMDLFLOGGUID<11100000','10000');
PL/SQLproceduresuccessfullycompleted.
Elapsed:00:00:18.54
方法虽好,但我应用在一个亿级数据库时还是觉得慢得不行。就算删一点点数据也觉得好象挺慢的。
【Oracle中大批量删除数据的方法】相关文章: