3

I have a list of records I want to process and the cursor iterates through them from a table. The procedure just exits when it hits an insert statement and it fails. Is there a way I can ignore the errors and continue processing the following records ?

Cursor C1: for each record: insert into table_t1(col1) values ('...'); <-- Insert statement fails for record 'n' End cursor

I would like for it to not exit out but continue processing from n+1 to the end of cursor.

Any help appreciated.

1
  • You can always catch the error and CHOOSE to do nothing about it.... – Joishi Bodio Jan 8 '15 at 16:58
5

Found it.

You have to declare a continue handler instead of an exit handler. That way even if there is an exception, it goes into the handler and continues with the next record.

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING

BEGIN ... Code that handles the exception/warning ... END

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.