我收到错误#1329-无数据-在MySQL中获取,选择或处理了零行 [英] I am getting error #1329 - No data - zero rows fetched, selected, or processed in MySQL
问题描述
以下代码中出现错误.错误为#1329-无数据-提取,选择或处理了零行.这到底是什么意思,我做错了什么? 谢谢
I am getting an error in the following code below. The error is #1329 - No data - zero rows fetched, selected, or processed. What exactly does this mean and what is it that i am doing incorrectly? Thanks
create procedure cursorproc(OUT p_out DECIMAL(10,2)) begin
declare l_salary, l_total DECIMAL(10,2);
declare cur_1 cursor for select line_distance from elements;
open cur_1;
set l_total = 0;
loop
fetch cur_1 into l_salary;
set l_total = l_total + l_salary;
end loop;
close cur_1;
set p_out = l_total;
end;
推荐答案
在没有更多数据的情况下,应为游标DECLARE HANDLER
:在
You should a DECLARE HANDLER
for the cursor when no more data is found: in docs you can find about how to do so.
使用
DECLARE handler_type HANDLER FOR condition_value[,...] sp_statement
其中处理程序类型为以下类型之一:CONTINUE, EXIT or UNDO
Where handler type is one of: CONTINUE, EXIT or UNDO
条件值是SQLSTATE [VALUE] sqlstate_value | condition_name | SQLWARNING | NOT FOUND | SQLEXCEPTION | mysql_error_code
之一.在这种情况下,NOT FOUND
是您(可能)正在寻找的东西.
Condition value is one of SQLSTATE [VALUE] sqlstate_value | condition_name | SQLWARNING | NOT FOUND | SQLEXCEPTION | mysql_error_code
. In this case NOT FOUND
is what you're (maybe) looking for.
所以您的代码将变成这样:
So your code would become something like this:
CREATE PROCEDURE cursorproc(OUT p_out DECIMAL(10,2))
BEGIN
DECLARE l_salary, l_total DECIMAL(10,2);
DECLARE _continue INT DEFAULT 0;
DECLARE cur_1 CURSOR FOR SELECT line_distance FROM elements;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET _continue =1;
OPEN cur_1;
SET l_total = 0;
REPEAT
FETCH cur_1 INTO l_salary;
SET l_total = l_total + l_salary;
UNTIL _continue = 1;
END REPEAT;
CLOSE cur_1;
SET p_out = l_total;
END;
还请查看 docs 以获取更多信息.
Also review the docs for further information.
这篇关于我收到错误#1329-无数据-在MySQL中获取,选择或处理了零行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!