问题描述
我有一个不需要返回任何值的存储过程.它运行顺利,没有任何问题.但是,它在完成运行后输出错误消息:
I have a stored procedure which does not need to return any values. It runs smoothly and without any problem. However, it outputs an error message after finishing its run:
错误:无数据 - 提取、选择或处理零行
Error: No data - zero rows fetched, selected, or processed
我怎样才能摆脱这个错误信息?
How can I get rid of this error message?
CREATE PROCEDURE `testing_proc`()
READS SQL DATA
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE l_name VARCHAR(20);
DECLARE my_cur CURSOR FOR
SELECT name FROM customer_tbl;
OPEN my_cur;
my_cur_loop:
LOOP FETCH my_cur INTO l_name;
IF done = 1 THEN
LEAVE my_cur_loop;
END IF;
INSERT INTO names_tbl VALUES(l_name);
END LOOP my_cur_loop;
CLOSE my_cur;
END
推荐答案
我猜你忘了在你的帖子中包含以下行:
I guess you just forgot to include the following line in your post:
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
您的代码是正确的,但 mysql 的错误/奇怪的行为导致即使处理了警告也会出现.您可以避免这种情况,如果您将虚拟"语句添加到调用表并成功的过程的末尾,这将清除警告.(参见 http://dev.mysql.com/doc/refman/5.5/en/show-warnings.html)在你的情况下:
Your code is correct, but bug/strange behaviour of mysql causes the warning to appear even if it was handled. You can avoid that if you add a "dummy" statement to the end of your procedure that invovles a table and is successful, this will clear the warning. (See http://dev.mysql.com/doc/refman/5.5/en/show-warnings.html) In your case:
SELECT name INTO l_name FROM customer_tbl LIMIT 1;
在循环结束之后.在 MySQL 5.5.13 上,警告消失,在 Linux 和 Windows 上.我评论了 MySQL Bug 60840,我希望他们在未来的某个时间修复它......
after the end of the loop. On MySQL 5.5.13 the warning disappears, on Linux and Windows. I commented on MySQL Bug 60840 and I hope they will fix it some time in the future...
这篇关于如何摆脱“错误 1329:无数据 - 提取、选择或处理零行"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!