user887364
user887364

Reputation: 1

mysql cursor execution

ERROR -


Error

SQL query:

call cursorproc(
@p_out
);

MySQL said: Documentation

1329 - No data - zero rows fetched, selected, or processed


AFTER EXECUTING - called stored procedure

call cursorproc (@p_out);
select @p_out as temp;

FOLLOWING CODE EXECUTED SUCCESSFULLY - stored procedure

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;

Any solution to this where exactly we are missing? Help on this would be appreciated.

Upvotes: 0

Views: 897

Answers (1)

Devart
Devart

Reputation: 121902

You should check end of dataset while reading data. Have a look at example here - cursors.

Also, I'd suggest you to avoid opening cursor -

SELECT SUM(line_distance) INTO @var FROM  elements;
SELECT @var;

Upvotes: 1

Related Questions