Oracle 5.0 Reference Manual page 1166

Table of Contents

Advertisement

13.6.7.1.
DECLARE ... CONDITION
DECLARE
condition_name
condition_value:
mysql_error_code
| SQLSTATE [VALUE]
The
DECLARE ... CONDITION
a condition that needs specific handling. The name can be referred to in a subsequent
statement (see
HANDLER
Condition declarations must appear before cursor or handler declarations.
The
condition_value
SQLSTATE value (a 5-character string literal). You should not use MySQL error code 0 or SQLSTATE
values that begin with '00', because those indicate success rather than an error condition. For a list of
MySQL error codes and SQLSTATE values, see
Using names for conditions can help make stored program code clearer. For example, this handler
applies to attempts to drop a nonexistent table, but that is apparent only if you know the meaning of
MySQL error code 1051:
DECLARE CONTINUE HANDLER FOR 1051
BEGIN
-- body of handler
END;
By declaring a name for the condition, the purpose of the handler is more readily seen:
DECLARE no_such_table CONDITION FOR 1051;
DECLARE CONTINUE HANDLER FOR no_such_table
BEGIN
-- body of handler
END;
Here is a named condition for the same condition, but based on the corresponding SQLSTATE value
rather than the MySQL error code:
DECLARE no_such_table CONDITION FOR SQLSTATE '42S02';
DECLARE CONTINUE HANDLER FOR no_such_table
BEGIN
-- body of handler
END;
13.6.7.2.
DECLARE ... HANDLER
DECLARE
handler_action
FOR
condition_value
statement
handler_action:
CONTINUE
| EXIT
| UNDO
condition_value:
mysql_error_code
| SQLSTATE [VALUE]
|
condition_name
| SQLWARNING
| NOT FOUND
| SQLEXCEPTION
The
DECLARE ... HANDLER
If one of these conditions occurs, the specified
Condition Handling
Syntax
CONDITION FOR
condition_value
sqlstate_value
statement declares a named error condition, associating a name with
Section 13.6.7.2,
"DECLARE ... HANDLER
for
DECLARE ... CONDITION
Syntax
HANDLER
[, condition_value] ...
sqlstate_value
statement specifies a handler that deals with one or more conditions.
1146
can be a MySQL error code (a number) or an
Section C.3, "Server Error Codes and
executes.
statement
DECLARE ...
Syntax").
Messages".
can be a simple
statement

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents