mySql procedure increment variable?
|September 15, 2014||Posted by forumadmin under TechQns||
Is there a way to rewrite this so that the position indicator in the function SPLIT_STR will increment with each loop? The field that this is parsing has up to 40 comma separated values and i want to insert each of them into the Tmp table. I have moved that function below the fetch statement and attempted to add in into the cursor and nothing seems to work. If I change this to read SPLIT_STR(tags,”,”,1) the table populates with that first pass just fine.
BEGIN DECLARE a INT Default 0; DECLARE str VARCHAR (255); DECLARE done INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT SPLIT_STR(tags,",",a) from Post where isPublished = 1; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; OPEN cur1; REPEAT FETCH cur1 INTO str; SET a=a+1; IF NOT done THEN INSERT into Tmp values(str); END IF; UNTIL done END REPEAT; CLOSE cur1; END
|Asked By – user1827601||Read Answers|