When a warning with not FOUND (no data) is encountered, a conditional handle containing a clear warning statement is used to process the program and exit the handle. This issue was resolved after the MySQL5.6.3 version, so the workaround is not necessary.
Workaround:
DECLARE CONTINUE HANDLER for not FOUND BEGIN
SET done=1 SELECT 1 to @handler_invoked from (SELECT 1) as T; END;
Source:Click the link (http://dev.mysql.com/doc/refman/5.5/en/condition-handling.html) and scroll to the bottom for details but T He fix is to include a successful select INSIDE the CONTINUE HANDLER:
Original:
Before MySQL 5.6.3, if a statement that generates a warning or error causes a condition handler to be invoked, the handler May isn't clear the diagnostic area. This might leads to the appearance that the handler is not invoked. The following discussion demonstrates the issue and provides a workaround.
Suppose. A table is t1
empty. The following procedure selects from it, raising a No Data condition:
CREATE PROCEDURE p1 () BEGIN DECLARE a INT; DECLARE CONTINUE HANDLER for not FOUND BEGIN SET @handler_invoked = 1; END; SELECT C1 to a from T1; END;
As can be seen from the following sequence of statements, the condition are not cleared by handler invocation (otherwise, t He SHOW WARNINGS
output would be empty). @handler_invoked
But as can is seen by the value of, the handler is indeed invoked (otherwise its value would is 0).
mysql> SET @handler_invoked = 0;
Query OK, 0 rows Affected (0.00 sec) mysql> call P1 ();
Query OK, 0 rows affected, 1 Warning (0.00 sec) mysql> SHOW WARNINGS;
+---------+------+-----------------------------------------------------+| Level | Code | Message |+---------+------+--------------------------------------------------- --+| Warning | 1329 | No Data-zero rows fetched, selected, or processed |+---------+------+------------------------------------------------ -----+1 Row in Set (0.00 sec) mysql> SELECT @handler_invoked;
+------------------+| @handler_invoked |+------------------+| 1 |+------------------+1 row in Set (0.00 sec)
To work around the issue, use a condition handler containing a statement that clears warnings:
CREATE PROCEDURE p1 () BEGIN DECLARE a INT; DECLARE CONTINUE HANDLER for not FOUND BEGIN SELECT 1 to @handler_invoked from (SELECT 1) as T; END; SELECT C1 to a from T1; END;
This works for CONTINUE
and EXIT
handlers.
This issue are resolved as of MySQL 5.6.3 and no workaround is needed.
Error resolution Mysql-event Scheduler:no Data-zero rows fetched, selected, or processed