SQL Reference

SIGNAL SQLSTATE

The SIGNAL SQLSTATE statement is used to signal an error. It causes an error to be returned with the specified SQLSTATE and the specified diagnostic-string.

Invocation

The SIGNAL SQLSTATE statement can only be used as a triggered SQL statement within a trigger.

Authorization

No authorization is required to execute this statement.

Syntax

>>-SIGNAL--SQLSTATE--string-constant---(--diagnostic-string--)--><
 

Description

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 application-defined SQLSTATEs as follows:

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

diagnostic-string
An expression with a type of CHAR or VARCHAR that returns a character string of up to 70 bytes that describes the error condition. If the string is longer than 70 bytes, it will be truncated.

Example

Consider an order system that records orders in an ORDERS table (ORDERNO, CUSTNO, PARTNO, QUANTITY) only if there is sufficient stock in the PARTS tables.

 CREATE TRIGGER check_avail
        NO CASCADE BEFORE INSERT ON orders
        REFERENCING NEW AS new_order
        FOR EACH ROW MODE DB2SQL
        WHEN (new_order.quantity > (SELECT on_hand FROM parts
                                    WHERE new_order.partno=parts.partno))
          BEGIN ATOMIC
            SIGNAL SQLSTATE '75001' ('Insufficient stock for order');
          END


[ Top of Page | Previous Page | Next Page ]