Oracle 5.0 Reference Manual page 1168

Table of Contents

Advertisement

->
INSERT INTO test.t VALUES (1);
->
SET @x = 3;
->
END;
->
//
Query OK, 0 rows affected (0.00 sec)
mysql>
CALL handlerdemo()//
Query OK, 0 rows affected (0.00 sec)
mysql>
SELECT @x//
+------+
| @x
|
+------+
| 3
|
+------+
1 row in set (0.00 sec)
Notice that
is
after the procedure executes, which shows that execution continued to the end
@x
3
of the procedure after the error occurred. If the
present, MySQL would have taken the default action (EXIT) after the second
constraint, and
PRIMARY KEY
To ignore a condition, declare a
example:
DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN END;
The scope of a block label does not include the code for handlers declared within the block. Therefore,
the statement associated with a handler cannot use
enclose the handler declaration. Consider the following example, where the
of retry:
CREATE PROCEDURE p ()
BEGIN
DECLARE i INT DEFAULT 3;
retry:
REPEAT
BEGIN
DECLARE CONTINUE HANDLER FOR SQLWARNING
BEGIN
ITERATE retry;
END;
IF i < 0 THEN
LEAVE retry;
END IF;
SET i = i - 1;
END;
UNTIL FALSE END REPEAT;
END;
The
label is in scope for the
retry
handler, so the reference there is invalid and results in an error:
ERROR 1308 (42000): LEAVE with no matching label: retry
To avoid references to outer labels in handlers, use one of these strategies:
• To leave the block, use an
handler body can be empty:
DECLARE EXIT HANDLER FOR SQLWARNING BEGIN END;
Otherwise, put the cleanup statements in the handler body:
DECLARE EXIT HANDLER FOR SQLWARNING
BEGIN
block cleanup statements
END;
Condition Handling
DECLARE ... HANDLER
would have returned 2.
SELECT @x
handler for it and associate it with an empty block. For
CONTINUE
# illegal
# legal
statement within the block. It is not in scope for the
IF
handler. If no block cleanup is required, the
EXIT
1148
statement had not been
or
to refer to labels for blocks that
ITERATE
LEAVE
failed due to the
INSERT
block has a label
REPEAT
CONTINUE
BEGIN ... END

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents