Condition handlers can be either SQLSTATE-based, generic, or associated with an user-defined condition.
SQLSTATE-based Condition Handlers
Execution of the SQL statements within a stored procedure may result in certain completion, exception, or warning conditions. These conditions are posted to the SQLSTATE status variable. You can declare a condition handler and associate it with one or more SQLSTATE values. The condition handler will execute its actions when the conditions represented by the specified SQLSTATE values occur during stored procedure execution.
Generic Conditions and Handlers
Generic conditions are represented by the keywords SQLEXCEPTION, SQLWARNING, or NOT FOUND. You can declare a condition handler and associate it with one or more generic conditions instead of specific SQLSTATE values. The condition handler will execute its actions when the specified generic conditions occur during stored procedure execution.
Condition Handlers for Condition Names
SQLSTATE is a 5-character string value. You can declare a mnemonic name and associate it with an SQLSTATE value to make it easier to remember what condition the SQLSTATE value represents. You can declare a condition handler and associate it with one or more condition names. The condition handler will execute its actions when the conditions identified by the condition names or the associated SQLSTATE values occur during stored procedure execution.
User-Defined Conditions and Handlers
You can define custom conditions by declaring a condition name without associating it with an SQLSTATE value. This is useful if the conditions represented by the SQLSTATE values do not meet your needs. You can declare a condition handler and associate it with one or more user-defined conditions. The condition handler will execute its actions when the user-defined conditions occur during stored procedure execution. You can use the SIGNAL statement to explicitly raise a user-defined condition.
Related Information
- Execution of the SQL statements within a stored procedure, see DECLARE HANDLER (Basic Syntax).
- Behavior of the generic condition handlers, see DECLARE HANDLER (SQLEXCEPTION Type), DECLARE HANDLER (SQLWARNING Type) and DECLARE HANDLER (NOT FOUND Type).
- Declaring a condition name, see DECLARE CONDITION.
- Declaring a user-defined condition and associating it with a condition handler, see DECLARE CONDITION and DECLARE HANDLER (Basic Syntax).
- SIGNAL statement, see SIGNAL.