Condition Declaration
The DECLARE CONDITION statement defines the name of a condition when it occurs fires an exception handler. The condition can be an error condition that is identified by a SQLSTATE code, a DBMSERROR number, or a predefined condition name.
A condition name for a SQLSTATE or DBMSERROR is equivalent to that SQLSTATE or DBMSERROR. For instance, given the declaration:
DECLARE zero_divide CONDITION FOR SQLSTATE '22012'; the two statements:
SIGNAL SQLSTATE ‘22012’;
SIGNAL zero_divide;
are exactly equivalent. A user-defined condition name that does not specify SQLSTATE or DBMSERROR does not correspond to any system generated error; thus, a handler for such a user-defined condition can only be invoked using SIGNAL or RESIGNAL.
Condition Declaration Format
The condition declaration has the following format:
DECLARE condition_name CONDITION [FOR SQLSTATE or DBMSERROR]
condition_name
Specifies the condition name. The condition name can be a user-defined condition or a predefined condition.
state_or_error_value
Specifies the error.
Valid values are:
• SQLSTATE [VALUE] string_literal
Example: SQLSTATE '22012'
• DBMSERROR [VALUE] integer_constant | string_literal
The integer value is what would be retrieved by the predefined variable IIERRORNUMBER.
Examples: DBMSERROR 4111 or DBMSERROR 'E_US100F'
Last modified date: 12/06/2024