错误解决mysql - Event Scheduler: No data - zero rows fetched, selected, or processed

本文讨论了在MySQL查询中遇到NOTFOUND警告时的问题及其解决方法。在MySQL 5.6.3之前的版本中,若查询引发警告或错误,可能导致条件处理器未正确清除诊断区域,从而出现误报。文章提供了工作-around解决方案,即在条件处理器中包含清除警告的语句。此外,自MySQL 5.6.3版本起,此问题已被解决,因此该解决方法不再必要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当遇到一个NOT FOUND(无数据)的警告时,使用一个包含清除警告语句的条件句柄处理,就可以继续处理程序并退出句柄。
这个问题在MySQL5.6.3之后的版本已经解决了,所以该解决方法不是必要的。
解决方法:   
  DECLARE CONTINUE HANDLER FOR NOT FOUND
    BEGIN
    SET done=1 SELECT 1 INTO @handler_invoked FROM (SELECT 1) AS t; END;
来源:Click the link( http://dev.mysql.com/doc/refman/5.5/en/condition-handling.html) and scroll to the bottom for details but the fix was to include a successful select INSIDE the CONTINUE HANDLER:
 
原文:

Before MySQL 5.6.3, if a statement that generates a warning or error causes a condition handler to be invoked, the handler may not clear the diagnostic area. This might lead to the appearance that the handler was not invoked. The following discussion demonstrates the issue and provides a workaround.

Suppose that a table t1 is 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 INTO a FROM t1;
END;

As can be seen from the following sequence of statements, the condition is not cleared by handler invocation (otherwise, the SHOW WARNINGS output would be empty). But as can be seen by the value of @handler_invoked, the handler was indeed invoked (otherwise its value would be 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 this 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 INTO @handler_invoked FROM (SELECT 1) AS t;
    END;
  SELECT c1 INTO a FROM t1;
END;

This works for CONTINUE and EXIT handlers.

This issue is resolved as of MySQL 5.6.3 and no workaround is needed.

 

 

 

转载于:https://www.cnblogs.com/gamir/p/4307772.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值