Please help me.. I am declaring cursor with IN clause value getting from other table where the value will be with comma (,) seprated and storing that into a variable and giving to the IN clause.
Here is my code:
CREATE DEFINER=`xxx`@`%` PROCEDURE `procedurename`(
OUT examDetails VARCHAR(2500)
)
BEGIN
DECLARE v_examType VARCHAR(50);
DECLARE v_minMarks INT(10);
DECLARE v_time INT(10);
DECLARE v_noOfQuestions INT(10);
DECLARE v_subTopicIds VARCHAR(50);
DECLARE v_subtopicname VARCHAR(50);
DECLARE v_result VARCHAR(2500) DEFAULT '';
DECLARE v_temp INT(20);
DECLARE cur1 CURSOR FOR SELECT ExamType,MinMarks,TIME,NoOfQuestions,SubTopicIds FROM tblCreSetExam;
select ExamType,MinMarks,Time,NoOfQuestions,SubTopicIds from tblCreSetExam
OPEN cur1;
FETCH FROM cur1 INTO v_examType,v_minMarks,v_time,v_noOfQuestions,v_subTopicIds;
declare cur2 cursor for select SubTopicName from tblEcertSubTopics where Id in (v_subTopicIds);
v_result = CONCAT(v_result,v_examType,'!',v_minMarks,'!',v_time,'!',v_noOfQuestions,'!');
open cur2;
fetch from cur2 into v_subtopicname;
v_result = CONCAT(v_result,v_subtopicname,'!');
close cur2;
v_temp = LENGTH(v_result)-1;
v_result = SUBSTRING(v_result,1,v_temp);
v_result = CONCAT(v_result,'^')
CLOSE cur1;
SET examDetails = v_result;
END$$
DELIMITER ;
But i am getting this error:
Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your
MySQLserver version for the right syntax to use near 'declare cur2 cursor for select
column1 from table1 where Id in (' at line 20
do any one know why this is getting.. Thanks in advance