https://gist.github.com/ntomka/fbf8e8b48690cecafe39
CREATE FUNCTION SPLIT_STRING(str VARCHAR(255), delim VARCHAR(12), pos INT)
RETURNS VARCHAR(255)
DETERMINISTIC
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, pos),
LENGTH(SUBSTRING_INDEX(str, delim, pos-1)) + 1),
delim, '');
用法和內建的function一樣。例如下例會顯示pear。
SELECT SPLIT_STRING('apple, pear, melon', ',', 2)