I have create a mysql Procedure. here its code
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE a , b, d TEXT;
DECLARE c INT Default 0;
DECLARE cur1 CURSOR FOR SELECT id, school_id FROM my_list;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO a, b;
IF done THEN
LEAVE read_loop;
END IF;
insertSchool: LOOP
SET c = c + 1;
d = SUBSTRING_INDEX(b, ',', c);
IF d = "" THEN
LEAVE insertSchool;
END IF;
INSERT INTO my_school (my_id, school_id) VALUES (a,b);
END LOOP insertSchool;
END LOOP;
CLOSE cur1;
END
In this cur1 has school_id as string it contain school ids in comma separated. i want split these ids and store in different table. but this line d = SUBSTRING_INDEX(b, ',', c); shows the error. can anyone please provide solution how to use SUBSTRING_INDEX in procedure?