1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| DROP FUNCTION IF EXISTS `SPLIT_STR`; delimiter $$ CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255)
BEGIN DECLARE i INT DEFAULT 0; DECLARE s text DEFAULT ''; 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)>0 then SET s = CONCAT(s,delim,x); end if; leave myloop; end if; END LOOP myloop; RETURN right(s,length(s)-length(delim));
DROP FUNCTION IF EXISTS `SPLIT_STR`; delimiter $$ CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255)
BEGIN DECLARE i INT DEFAULT 0; DECLARE s text DEFAULT ''; 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)>0 then SET s = CONCAT(s,delim,x); end if; leave myloop; end if; END LOOP myloop; RETURN right(s,length(s)-length(delim)); END $$
|