I have a situation where I have to pass a comma-separated string to a MySQL procedure and split this string and paste these values ββas strings into the table.
As below
For example, if I passed the string "jhon, swetha, sitha" to the mysql procedure, then it should break this line with a comma and insert these values ββas 3 entries into the table.
CREATE PROCEDURE new_routine (IN str varchar(30)) BEGIN DECLARE tmp varchar(10); DECLARE inc INT DEFAULT 0; WHILE INSTR(str, ',') DO SET tmp = SUBSTRING(SUBSTRING_INDEX(str,',',inc),LENGTH(SUBSTRING_INDEX(str,',',inc-1))+1),',',''); SET str = REPLACE(str, tmp, ''); //insert tmp into a table. END WHILE; END
But this did not work a single solution.
sql mysql stored-procedures
Harika choudary kanikanti
source share