SET v_insert_friend_idxs = CONCAT('1,2' , ','); WHILE (LOCATE(',', v_insert_friend_idxs) > 0) DO SET @v_friend_idx = SUBSTRING(v_insert_friend_idxs, 1, LOCATE(',',v_insert_friend_idxs)-1); SET v_insert_friend_idxs = SUBSTRING(v_insert_friend_idxs, LOCATE(',', v_insert_friend_idxs) + 1); SELECT @v_friend_idx; END WHILE;