SQL Reference

RESIGNAL Statement

The RESIGNAL statement is used to resignal an error or warning condition. It causes an error or warning to be returned with the specified SQLSTATE, along with optional message text.

Syntax

>>-RESIGNAL----+----------------------------------------+------><
               '-| signal-value |--+-----------------+--'
                                   '-| signal-info |-'
 
signal-value
 
                .-VALUE-.
|---+-SQLSTATE--+-------+--sqlstate-string-constant--+----------|
    '-condition-name---------------------------------'
 
signal-info
 
|---+---------------------------------------------------------+-|
    '-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.

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 an 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

This example detects a division by zero error. The IF statement uses a SIGNAL statement to invoke the overflow condition handler. The condition handler uses a RESIGNAL statement to return a different SQLSTATE value to the client application.

   CREATE PROCEDURE divide ( IN numerator INTEGER
                               IN denominator INTEGER
                               OUT result INTEGER
   LANGUAGE SQL
   CONTAINS SQL
   BEGIN
     DECLARE overflow CONDITION FOR SQLSTATE '22003';
       DECLARE CONTINUE HANDLER FOR overflow
       RESIGNAL SQLSTATE'22375' ;
       IF denominator = 0 THEN
       SIGNAL overflow;
     ELSE
        SET result = numerator / denominator;
     END IF;
   END


[ Top of Page | Previous Page | Next Page ]