SIGNAL statement

If an operation does not complete successfully automatically DB2 will raise a conditition. The SIGNAL statement can be used to raise a condition manually in the code.


 SIGNAL SQLSTATE <sqlstate> [SET MESSAGE_TEXT '<text>' ]


 create procedure myproc (in v_var01 integer)
    if v_var01 > 100 then
       signal SQLSTATE '70000' set message_text='The input parameter must be lower than 100!';
    end if;

Test of this example:

 call myproc(200);

 SQL0438N  Application raised error with diagnostic text: "The input parameter must be lower than 100!".  SQLSTATE=70000

Link to the DB2 Information Center: DB2 9.7 DB2 10.1 DB2 10.5