Associates a condition handler with one or more exception, completion, or user-defined conditions to be handled in a stored procedure.
ANSI Compliance
DECLARE HANDLER is ANSI/ISO SQL:2011-compliant.
Required Privileges
None.
Invocation
Executable control declaration.
Stored procedures only.
Syntax
DECLARE { CONTINUE | EXIT } HANDLER FOR { { sqlstate_state_spec | condition_name } [,...] | { SQLEXCEPTION | SQLWARNING | NOT FOUND } [,...] } handler_action_statement ;
Syntax Elements
- sqlstate_state_spec
SQLSTATE [VALUE] sqlstate_code
- CONTINUE
- The type of handler action to be executed.
- EXIT
- The type of handler action to be executed.
- sqlstate_code
- The five-character literal SQLSTATE code to be handled.
- SQLEXCEPTION
- Generic condition to be handled.
- SQLWARNING
- Generic condition to be handled.
- NOT FOUND
- Generic condition to be handled.
- condition_name
- the name of the condition to be handled.
- handler_action_statement
- either a single statement or multiple statements enclosed in a compound statement that define the handler action.
Usage Notes
You can specify one of the following in a handler declaration, but not both.
- a list of SQLSTATE values and/or condition names
- a list of generic conditions
You cannot repeat the same condition name, SQLSTATE code, or generic condition in handler declarations within the same compound statement.
You cannot specify both the condition name and the SQLSTATE value associated with the condition name in handler declarations within the same compound statement.
Related Information
- SQLSTATE codes and their meanings, see SQLSTATE Mappings.
- condition_name, see DECLARE CONDITION.
- Condition name and the SQLSTATE value associated with the condition name, see Condition Handler Rules.