1CREATE FUNCTION `SPLIT_STRING`(
2 str VARCHAR(255) ,
3 delim VARCHAR(12) ,
4 pos INT
5) RETURNS VARCHAR(255) CHARSET utf8 RETURN REPLACE(
6 SUBSTRING(
7 SUBSTRING_INDEX(str , delim , pos) ,
8 CHAR_LENGTH(
9 SUBSTRING_INDEX(str , delim , pos - 1)
10 ) + 1
11 ) ,
12 delim ,
13 ''
14);
15
16SELECT
17 -- keyword 1
18 SPLIT_STRING(`keywords`,',',1) AS keyword_1,
19 -- keyword 4, NOT trimmed
20 SPLIT_STRING(`keywords`,',',4) AS keyword_4,
21 -- keyword 4, trimmed
22 trim(SPLIT_STRING(`keywords`,',',4)) AS keyword_4_trimmed
23FROM `test`;