Handling SQL conditions in an SQL procedure

In an SQL procedure, you can specify how the program should handle certain SQL errors and SQL warnings.

About this task

If you do not include a handler or a RETURN statement in the SQL procedure, Db2 automatically returns any SQL conditions to the caller in the SQLCA.

Procedure

To handle SQL conditions, use one of the following techniques:

  • Include statements called handlers to tell the procedure to perform some other action when an error or warning occurs.
  • Include a RETURN statement in an SQL procedure to return an integer status value to the caller.
  • Include a SIGNAL statement or a RESIGNAL statement to raise a specific SQLSTATE and to define the message text for that SQLSTATE.
  • Force a negative SQLCODE to be returned by a procedure if a trigger calls the procedure.