Bug #77834 dynamic cursor gives error while executing
Submitted: 25 Jul 2015 12:21
Reporter: vivek toke Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:mysql 5.6 OS:Windows (windows 7)
Assigned to: CPU Architecture:Any

[25 Jul 2015 12:21] vivek toke
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 );