mysql把字符串拆成多行的方法:可以利用substring_index()函数来进行拆分,例如【substring_index(substring_index(a.chain,'_',b.topic_id + 1)】。
可以利用字符串截取函数substring_index来实现。
(推荐教程:mysql视频教程)
语法:
substring_index(str, delimiter, count)
说明:
返回一个 str 的子字符串,在 delimiter 出现 count 次的位置截取。如果 count > 0,从则左边数起,且返回位置前的子串;如果 count < 0,从则右边数起,且返回位置后的子串。
delimiter 是大小写敏感,且是多字节安全的。
举例:
select substring_index(substring_index(a.chain,'_',b.help_topic_id + 1),'_' ,- 1)as idfrom (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)
执行结果:
相关推荐:php培训
以上就是mysql如何把字符串拆成多行的详细内容。