贾斯汀,根据你的建议,我在这里添加了循环..
无论如何我们可以调整这个程序吗?我还没有测试。
在这里,我们只是从主表和子表中删除 90 天历史记录之前的记录。假设表有超过 20k 条记录要删除。在这里我为每条 5k 记录提交。如果我在这里错了,请告诉我?
create or replace
Procedure PURGE_CLE_ALL_STATUS
( days_in IN number )
IS
LV_EXCEPTIONID NUMBER;
i number := 0;
cursor s1 is
select EXCEPTIONID
from EXCEPTIONREC --- master table
where TIME_STAMP < (sysdate -days_in);
BEGIN
for c1 in s1 loop
delete from EXCEPTIONRECALTKEY -- child table
where EXCEPTIONID =c1.EXCEPTIONID ;
delete from EXCEPTIONREC
where EXCEPTIONID =c1.EXCEPTIONID;
i := i + 1;
if i > 5000 then
commit;
i := 0;
end if;
end loop;
commit;
close S1;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||
SQLCODE||' -ERROR- '||SQLERRM);
END;
/