阅读量:0
在MySQL中,可以使用SUBSTRING_INDEX函数来分割字符串。该函数的语法如下:
SUBSTRING_INDEX(str, delim, count)
- str:要分割的字符串
- delim:分隔符
- count:返回的子字符串的个数
例如,将"apple,orange,banana"分割成三个子字符串:
SELECT SUBSTRING_INDEX('apple,orange,banana', ',', 1) AS str1, SUBSTRING_INDEX(SUBSTRING_INDEX('apple,orange,banana', ',', 2), ',', -1) AS str2, SUBSTRING_INDEX('apple,orange,banana', ',', -1) AS str3;
输出结果为:
+--------+--------+--------+ | str1 | str2 | str3 | +--------+--------+--------+ | apple | orange | banana | +--------+--------+--------+