![background image](http://html1.mh-extra.com/html/oracle/5-0/5-0_reference-manual_16461961166.webp)
Condition Handling
1146
13.6.7.1.
DECLARE ... CONDITION
Syntax
DECLARE
condition_name
CONDITION FOR
condition_value
condition_value
:
mysql_error_code
| SQLSTATE [VALUE]
sqlstate_value
The
DECLARE ... CONDITION
statement declares a named error condition, associating a name with
a condition that needs specific handling. The name can be referred to in a subsequent
DECLARE ...
HANDLER
statement (see
Section 13.6.7.2, “
DECLARE ... HANDLER
Syntax”
).
Condition declarations must appear before cursor or handler declarations.
The
condition_value
for
DECLARE ... CONDITION
can be a MySQL error code (a number) or an
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
Section C.3, “Server Error Codes and Messages”
.
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
Syntax
DECLARE
handler_action
HANDLER
FOR
condition_value
[,
condition_value
] ...
statement
handler_action
:
CONTINUE
| EXIT
| UNDO
condition_value
:
mysql_error_code
| SQLSTATE [VALUE]
sqlstate_value
|
condition_name
| SQLWARNING
| NOT FOUND
| SQLEXCEPTION
The
DECLARE ... HANDLER
statement specifies a handler that deals with one or more conditions.
If one of these conditions occurs, the specified
statement
executes.
statement
can be a simple
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...