The SIGNAL statement is used to signal an error or warning condition. It causes an error or warning to be returned with the specified SQLSTATE, along with optional message text.
Syntax
.-VALUE-. >>-SIGNAL----+-SQLSTATE--+-------+--sqlstate-string-constant--+-> '-condition-name---------------------------------' >-----+---------------------------------------------------------+->< '-SET--MESSAGE_TEXT-- = --+-variable-name--------------+--' '-diagnostic-string-constant-'
Description
If the SQLSTATE does not conform to these rules, an error is raised (SQLSTATE 428B3).
Notes
+438 if the SQLSTATE begins with '01' or '02'
-438 otherwise
Any valid SQLSTATE value can be used in the SIGNAL statement. However, it is recommended that programmers define new SQLSTATEs based on ranges reserved for applications. This prevents the unintentional use of an SQLSTATE value that might be defined by the database manager in a future release.
Examples
An SQL procedure for an order system that signals an application error when a customer number is not known to the application. The ORDERS table includes a foreign key to the CUSTOMER table, requiring that the CUSTNO exist before an order can be inserted.
CREATE PROCEDURE SUBMIT_ORDER (IN ONUM INTEGER, IN CNUM INTEGER, IN PNUM INTEGER, IN QNUM INTEGER) SPECIFIC SUBMIT_ORDER MODIFIES SQL DATA LANGUAGE SQL BEGIN DECLARE EXIT HANDLER FOR SQLSTATE VALUE '23503' SIGNAL SQLSTATE '75002' SET MESSAGE_TEXT = 'Customer number is not known'; INSERT INTO ORDERS (ORDERNO, CUSTNO, PARTNO, QUANTITY) VALUES (ONUM, CNUM, PNUM, QNUM); END