Description:
i am writing stored procedure, in which i am using cursor for iterating the column values. while writing the cursor the condition is table name is supplied as parameter for declare cursor statement in for clause.
for e.g. DECLARE c1 CURSOR FOR SELECT prod_id FROM product;
here i want to supply the table name product as parameter
i used concat and prepare for making the declare statement and after call execute but fails
it gives "cursor is not declared"
how can write the declare cursor statement dynamically in stored procedure.
How to repeat:
write simple store procedure
in which write simple cursor
instead of writing the static statement like
DECLARE c1 CURSOR FOR SELECT prod_id FROM product;
send table name as parameter
in short you are preparing the declare statements using string and variable
using concat or prepare
like
set @sqltext2 := concat( DECLARE c1 CURSOR FOR SELECT prod_id FROM ', table_name );