mysql 5.6 1329,我收到错误#1329-无数据-在MySQL中获取,选择或处理了零行

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;

解决方案

You should a DECLARE HANDLER for the cursor when no more data is found: in docs you can find about how to do so.

Use

DECLARE handler_type HANDLER FOR condition_value[,...] sp_statement

Where handler type is one of: CONTINUE, EXIT or UNDO

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;

Also review the docs for further information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值