Way to catch all type of rised signals in DB2 SQL-PL via a declare handler

AngocA picture AngocA · Feb 10, 2014 · Viewed 7.1k times · Source

I want to treat all types of generated signals in my code. I know how to catch a specific one with a Declare Handler, however I would like all of them.

For example, here I catch the 72822 signal.

DECLARE EXIT HANDLER FOR SQLSTATE '72822'
  BEGIN
    IF ( var = 'OK' )
      RESIGNAL SQLSTATE '72623' SET MESSAGE_TEXT = 'Got SQLSTATE 72822';
    ELSE
      RESIGNAL SQLSTATE '72319' SET MESSAGE_TEXT = var;
  END;

I will call a stored procedure that I do not know the code, and I have to be able to deal with all possible signals (for example insert the signal code in a table.)

I would like something like

DECLARE EXIT HANDLER FOR ALL

Answer

mustaccio picture mustaccio · Feb 10, 2014

That would be DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, I think.

http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0004239.html