SQL Reference

SIGNAL Statement

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

SQLSTATE VALUE sqlstate-string-constant
The specified string constant represents an SQLSTATE. It must be a character string constant with exactly 5 characters that follow the rules for SQLSTATEs:

If the SQLSTATE does not conform to these rules, an error is raised (SQLSTATE 428B3).

condition-name
Specifies the name of the condition. The condition name must be unique within the procedure and can only be referenced within the compound statement in which it is declared.

SET MESSAGE_TEXT=
Specifies a string that describes the error or warning. The string is returned in the SQLERRMC field of the SQLCA. If the actual string is longer than 70 bytes, it is truncated without warning. This clause can only be specified if a SQLSTATE or condition-name is also specified (SQLSTATE 42601).

variable-name
Identifies an SQL variable that must be declared within the compound statement. The SQL variable must be defined as a CHAR or VARCHAR data type.

diagnostic-string-constant
Specifies a character string constant that contains the message text.

Notes

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


[ Top of Page | Previous Page | Next Page ]