mysql字符串分割操作

Posted Enjoy Life

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql字符串分割操作相关的知识,希望对你有一定的参考价值。

SELECT \'1,2,3,4,5,6,7,8\' FROM dual;

-- 列转行分割
SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(a.path,\',\',b.help_topic_id + 1),\',\',-1)  
FROM  
(SELECT GROUP_CONCAT(REPLACE(path,\'/\',\',\')) AS path FROM department b WHERE department_type = 1) a
JOIN 
mysql.help_topic b 
ON b.help_topic_id < (LENGTH(a.path) - LENGTH(REPLACE(a.path,\',\',\'\')) + 1);



-- 测试
SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(a.path,\',\',b.help_topic_id + 1),\',\',-1) as path
FROM  
(SELECT \'1,2,3,4,5,6,7,8\' as path FROM dual) a
JOIN 
mysql.help_topic b 
ON b.help_topic_id < (LENGTH(a.path) - LENGTH(REPLACE(a.path,\',\',\'\')) + 1);

测试结果:

 

以上是关于mysql字符串分割操作的主要内容,如果未能解决你的问题,请参考以下文章

如何从 RCNN 中裁剪分割的对象?

mysql中将一列以逗号分隔的值分割成多列显示?

如何标记从卷积神经网络的分割算法生成的图像片段?

字符串分割strtok_s

python常用操作之使用多个界定符(分隔符)分割字符串

python常用操作之使用多个界定符(分隔符)分割字符串