-- substring_index(要截取的字符串,分割符号,从1开始)
SELECT
substring_index(substring_index(a.chain,'_',b.help_topic_id + 1 ) ,'_',-1)
FROM
(select '1_11_1223_1242' as chain) a
JOIN mysql.help_topic b ON b.help_topic_id <(length(a.chain) - length( replace(a.chain, '_', '') ) + 1)
-- 链接 mysql.help_topic help_id_topic_id 是一个自增的列 如: 1,2,3,4,5,6…… 可以通过help_topic_id < 字符串长度-替换分隔符为空格之后的字符串长度 的结果+1
MySQL实现字符串拆分
于 2023-03-20 10:48:58 首次发布
该文演示了如何在MySQL中使用substring_index函数,结合help_topic_id从连锁字符串中提取信息。通过将链式字符串1_11_1223_1242和help_topic_id关联,可以获取特定位置的子串,特别是在处理多段结构的数据时。
摘要由CSDN通过智能技术生成