Deleting a large number of records using PL/SQL

流过昼夜 提交于 2019-12-06 04:48:36

What resources are you concerned about consuming? A single DELETE statement is going to be the most efficient approach*. Assuming this is something that needs to be done regularly, the database should really be sized appropriately in terms of UNDO tablespace to allow you to do a single DELETE.

Actually, taking a step back, the most efficient approach would be to partition the table by the UPDT_TIMESTMP and drop the older partition(s). But partitioning is an extra cost option on top of your enterprise edition license and partitioning the table may have other impacts on the system.

If you really, really need to delete rows in batches with interim commits, this appears to be a pretty reasonable implementation. I would really only consider this if the single DELETE statement took a substantial fraction of my nightly processing window and I was concerned that the DELETE might fail after a couple hours forcing a rollback and a restart of the entire process. Deleting in batches would be slower than doing the single DELETE normally but it would be easier to restart.

The recommendation to use BULK COLLECT and FORALL doesn't make sense in this particular case. It would apply to the more common case where someone is selecting data from one or more source tables, doing some processing in PL/SQL, and then writing the data out to a destination table. It would be more efficient to do that via bulk operations rather than via slow row-by-row processing. But it would be even more efficient to do it as a single INSERT ... SELECT.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!