Hi All,
I have a problem with my MySQL Stored Procedure.
I am writing a SELECT query using dynamic table name.
For framing such dynamic queries, I need to use Prepared Statement and then EXECUTE it.
But to fetch the fields, when I try to DECLARE CURSOR. I am getting Syntax Error.
Can anynody tell me how to use CUSRSOR for Prepared Statement.
Below, is my sample code.
CREATE PROCEDURE `test`(IN argCaseid INT,IN argGroupid INT)
BEGIN
SET @priya=CONCAT("SELECT * FROM abc");
prepare st1 FROM @priya;
EXECUTE st1;
DECLARE curTroubleTicket CURSOR FOR st1;
OPEN curTroubleTicket;
troubleticketloop: LOOP
FETCH curTroubleTicket INTO strcase,strgrp,strok;
SELECT strcase;
LEAVE troubleticketloop;
END LOOP;
CLOSE curTroubleTicket;
END
Regards,
Priya
(priya_vasanthakumar@sifycorp.com)
I have a problem with my MySQL Stored Procedure.
I am writing a SELECT query using dynamic table name.
For framing such dynamic queries, I need to use Prepared Statement and then EXECUTE it.
But to fetch the fields, when I try to DECLARE CURSOR. I am getting Syntax Error.
Can anynody tell me how to use CUSRSOR for Prepared Statement.
Below, is my sample code.
CREATE PROCEDURE `test`(IN argCaseid INT,IN argGroupid INT)
BEGIN
SET @priya=CONCAT("SELECT * FROM abc");
prepare st1 FROM @priya;
EXECUTE st1;
DECLARE curTroubleTicket CURSOR FOR st1;
OPEN curTroubleTicket;
troubleticketloop: LOOP
FETCH curTroubleTicket INTO strcase,strgrp,strok;
SELECT strcase;
LEAVE troubleticketloop;
END LOOP;
CLOSE curTroubleTicket;
END
Regards,
Priya
(priya_vasanthakumar@sifycorp.com)