在这里,我们只是从主表和子表中删除 90 天历史记录之前的记录。假设表有超过 20k 条记录要删除。在这里,我为每 5k 条记录添加了提交。如果我在这里错了,请告诉我?
create or replace Procedure PURGE_CLE_ALL_STATUS ( days_in IN number )
IS
reccount NUMBER := 0;
CURSOR del_record_cur IS
SELECT EXCEPTIONID FROM EXCEPTIONREC
WHERE trunc(TIME_STAMP) < trunc(sysdate - days_in );
BEGIN
FOR rec IN del_record_cur LOOP
delete from EXCEPTIONRECALTKEY -- child table
where EXCEPTIONID =rec.EXCEPTIONID ;
delete from EXCEPTIONREC -- master table
where EXCEPTIONID =rec.EXCEPTIONID;
reccount := reccount + 1;
IF (reccount >= 1000) THEN
COMMIT;
count := 0;
END IF;
commit;
END LOOP;
COMMIT;
DBMS_OUTPUT.PUT_LINE('Deleted ' || total || ' records from <OWNER>.<TABLE_NAME>.');
END;
/