Toad World® Forums

How to do Error Handling in DB2 Stored Proc?

Hi All,

I am very new to DB2 world and I would like to know the Implementation of Error Handling in DB2 stored procedures along with rollback.

Example Scenario: A db2 stored proc have different dml commands like Insert and updates. During the time of inserts and updates I need to implement error handling. Also if there is a dependency between Inserts and updates. If all the inserts got successful and something in the updates failed with in single stored procedure then all the inserts must rollback and should display the error message.

Thanks!!!

Waiting for the reply…

Hello DynoDb2,

Please see our Toad World Db2 Wiki. You can find there a lot of information about Db2 SP development.
https://www.toadworld.com/platforms/ibmdb2/w/wiki

About error handling you can read here:
https://www.toadworld.com/platforms/ibmdb2/w/wiki/7756.sql-error-handling

I would recommend you use a single transaction for each bunch of commands which needs to be done all or none.

Regards
Ondrej