statement such as
SET var_name =
(see
Section 13.6.1,
"BEGIN ... END
Handler declarations must appear after variable or condition declarations.
The
handler_action
statement:
• CONTINUE: Execution of the current program continues.
• EXIT: Execution terminates for the
declared. This is true even if the condition occurs in an inner block.
• UNDO: Not supported.
The
condition_value
conditions that activates the handler:
• 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
• A condition name previously specified with
associated with a MySQL error code or SQLSTATE value. See
Syntax".
CONDITION
•
is shorthand for the class of SQLSTATE values that begin with '01'.
SQLWARNING
•
is shorthand for the class of SQLSTATE values that begin with '02'. This is relevant
NOT FOUND
within the context of cursors and is used to control what happens when a cursor reaches the end
of a data set. If no more rows are available, a No Data condition occurs with SQLSTATE value
'02000'. To detect this condition, you can set up a handler for it (or for a
For an example, see
statements that retrieve no rows.
var_list
•
is shorthand for the class of SQLSTATE values that do not begin with '00', '01',
SQLEXCEPTION
or '02'.
If a condition occurs for which no handler has been declared, the action taken depends on the
condition class:
• For
SQLEXCEPTION
condition, as if there were an
the calling program handles the condition using the handler selection rules applied to its own
handlers.
• For
or
SQLWARNING
handler.
CONTINUE
The following example uses a handler for
mysql>
CREATE TABLE test.t (s1 INT, PRIMARY KEY (s1));
Query OK, 0 rows affected (0.00 sec)
mysql>
delimiter //
mysql>
CREATE PROCEDURE handlerdemo ()
->
BEGIN
->
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET @x2 = 1;
->
SET @x = 1;
->
INSERT INTO test.t VALUES (1);
->
SET @x = 2;
Condition Handling
value, or a compound statement written using
Compound-Statement
value indicates what action the handler takes after execution of the handler
BEGIN ... END
for
DECLARE ... HANDLER
Messages".
DECLARE ...
Section 13.6.6,
"Cursors". This condition also occurs for
conditions, the stored program terminates at the statement that raised the
handler. If the program was called by another stored program,
EXIT
conditions, the program continues executing, as if there were a
NOT FOUND
SQLSTATE
1147
Syntax").
compound statement in which the handler is
indicates the specific condition or class of
CONDITION. A condition name can be
Section 13.6.7.1,
NOT FOUND
'23000', which occurs for a duplicate-key error:
and
BEGIN
END
"DECLARE ...
condition).
SELECT ... INTO
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers