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
If the SQLSTATE does not conform to these rules an error occurs (SQLSTATE 428B3).
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