DROPFUNCTIONIFEXISTS `SPLIT_STR`; delimiter $$ CREATEFUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNSVARCHAR(255) BEGIN DECLARE i INTDEFAULT0; DECLARE s textDEFAULT''; myloop: LOOP SET i = i+pos; SET s = CONCAT(s,delim,left(x,pos)); SET x = right(x,length(x)-pos); if pos>length(x) then if length(x)>0then SET s = CONCAT(s,delim,x); endif; leave myloop; endif; ENDLOOP myloop; RETURN right(s,length(s)-length(delim)); END $$