MySQL——字符串拆分(含分隔符的字符串截取)

参看:https://blog.csdn.net/pjymyself/article/details/81668157?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.nonecase

例子:

https://bbs.csdn.net/topics/392362532?page=1&from=singlemessage

实际使用SQL语句:

SELECT
`a`.`user_name` AS `user_name`,
`a`.`user_id` AS `user_id`,
`a`.`unit` AS `unit`,
`a`.`topic_id` AS `topic_id`,
`a`.`topic_name` AS `topic_name`,
substring_index( substring_index( `a`.`field4`, '^', ( `b`.`id` + 1 ) ), '^',- ( 1 ) ) AS `field4`
FROM
(
`field4_view` `a`
JOIN `for_test` `b` ON (
(
`b`.`id` < ( ( length( `a`.`field4` ) - length( REPLACE ( `a`.`field4`, '^', '' ) ) ) + 1 )
)
)
)
WHERE
(
substring_index( substring_index( `a`.`field4`, '^', ( `b`.`id` + 1 ) ), '^',- ( 1 ) ) <> ''
)

原文地址:https://www.cnblogs.com/brianlai/p/13350584.html