Skip to content Skip to sidebar Skip to footer

Using A Cursor In A Stored Procedure To Loop Rows Mysql

Scenario: I have a stored procedure that gets data from a table based on 2 inputs: a date and a string (which is a column name). The first procedure is called from another procedur

Solution 1:

You have a couple of problems in your procedure. Firstly, as described in the manual:

DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.

So you need to move your

set@dateval= `wanted_date`;

after all the DECLAREs (including the cursor and continue handler).

Secondly, your declaration of colval is incorrect, string is not a valid data type and should be replaced with text:

declare colval text defaultnull;

Post a Comment for "Using A Cursor In A Stored Procedure To Loop Rows Mysql"