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.... Jan 8, 2015 at 16:58

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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