Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bulk Delete Operation using FORALL

User170058Nov 13 2019 — edited Nov 14 2019

Hi All,

I am doing a daily archive job . I am using the BULK COLLECT and FORALL to delete the rows from the table. All goes well as long as there are no exceptions .

My Code is as Below

BEGIN

  SELECT KEY BULK COLLECT INTO <VARAIBLE> FROM <TABLE> WHERE DATE <=<INPUT VALUE> ;

FORALL INX IN 1...<variable>.count SAVE EXCEPTIONS;

DELETE FROM <TABLE> where KEY=<variable>(INX);

log_del_rec_count:=SQL%ROWCOUNT;

EXCEPTION

WHEN BULK_EXCPTIO_ERR

   FOR I IN 1.. , ... LOOP

    <log error>

   END LOOP;

END;

AS long as there are no failures the value in log_del_rec_count matches the value of records delete. But one the failure occurs the rows returned are 0. Why does this happen. Should I use a FOR loop instead of FOR ALL .

Thanks & Regards

Hower

Comments
Post Details
Added on Nov 13 2019
4 comments
2,768 views