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 HANDLERfor the cursor when no more data is found: in docs you can find about how to do so.Use
Where handler type is one of:
CONTINUE, EXIT or UNDOCondition value is one of
SQLSTATE [VALUE] sqlstate_value | condition_name | SQLWARNING | NOT FOUND | SQLEXCEPTION | mysql_error_code. In this caseNOT FOUNDis what you’re (maybe) looking for.So your code would become something like this:
Also review the docs for further information.