SPLIT_STR

CREATE FUNCTION fn_split ( s TEXT , del CHAR(1) , i INT)
RETURNS VARCHAR(1024)
DETERMINISTIC -- always returns same results for same input parameters
SQL SECURITY INVOKER
BEGIN
DECLARE n INT ;
-- get max number of items
SET n = LENGTH(s) - LENGTH(REPLACE(s, del, '')) + 1;
IF i > n THEN
RETURN NULL ;
ELSE
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(s, del, i) , del , -1 ) ;
END IF;
END

posted on 2017-09-28 14:12  adolfmc  阅读(365)  评论(0编辑  收藏  举报