Performing massive delete

When you are performing massive delete, you are always at risk of filling up UNDO tablespace. Also, if the delete statement fails for some reason, you have to start from the beginning again. The only way to track the progress is by looking at v$sess longops table, and its not very convinient. The short PLSQL block below will do the gradual delete of the rows, its faster the the one DELETE statement and its easy to track, if you set your SERVEROUTPUT ON, it wil print out the progress on the sceen. This block will COMMIT after every 10000 rows.

   i_commit_int number:=0;
   for i in (select rowid from MYTABLE) loop
     delete from MYTABLE where rowid=i.rowid;
     if i_commit_int>=10000 then
        dbms_output.put_line('10k marker');
     end if;
   end loop;

Copyright © 2007, All rights reserved by RudnikConsulting Inc