我希望每 1000 行提交一次,直到所有记录都被删除,我们有超过一百万条记录要删除。
起初:
private static final String DELETE_OLD_REPORTS_FROM_REPORTING =
- "DELETE FROM A_REPORTING\n" +
- "WHERE ID IN(" +
- "SELECT ID FROM A_REPORTING\n" +
- "WHERE STATUS = 'LOADED'\n" +
- "AND CREATE_DT < TO_DATE(:createdDate, 'dd-mon-yyyy'))";
我正在考虑做这样的事情:
"BEGIN\n" +
"LOOP\n" +
"DELETE FROM A_REPORTING\n" +
"WHERE ID IN(" +
"SELECT ID FROM A_REPORTING\n" +
"WHERE STATUS = 'LOADED'\n" +
"AND CREATE_DT < TO_DATE(:createdDate, 'dd-mon-yyyy')\n+" +
"AND ROWNUM <= 10000);\n" +
"EXIT WHEN SQL%rowcount < 9999;\n" +
"COMMIT;\n" +
"END LOOP;\n"+
"COMMIT;\n" +
"END";
但是,有没有更好的方法来做到这一点?这是因为我们收到了 ORA-01555 错误:
ORA-01555: 快照太旧: 名称为 "%segname" 的回滚段号 %n 太小。