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 );

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.047 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.