MySQL直接⽤SQL分割字符串到数组承接上⽂:
主要思路其实⼀致:够造序列,然后结合MySQL的SUBSTRING_INDEX 函数的特性分割字符串。
SET@str="a,b,c,d,e,f,g,h,i,j,k" ;
SET@delim="," ;
SET@str_length=length(@str)- length( REPLACE (@str,@delim,'') )+1 ;
SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX( @str, @delim, tmp.seq),@delim, -1) as str_split
FROM
(
SELECT字符串截取 sql
s1.i + s2.i + s3.i + s4.i + s5.i + s6.i + s7.i + s8.i + s9.i+1AS seq
FROM ( SELECT0AS i UNION ALL SELECT1AS i ) s1
CROSS JOIN ( SELECT0AS i UNION ALL SELECT2AS i ) s2
CROSS JOIN ( SELECT0AS i UNION ALL SELECT4AS i ) s3
CROSS JOIN ( SELECT0AS i UNION ALL SELECT8AS i ) s4
CROSS JOIN ( SELECT0AS i UNION ALL SELECT16AS i ) s5
CROSS JOIN ( SELECT0AS i UNION ALL SELECT32AS i ) s6
CROSS JOIN ( SELECT0AS i UNION ALL SELECT64AS i ) s7
CROSS JOIN ( SELECT0AS i UNION ALL SELECT128AS i ) s8
CROSS JOIN ( SELECT0AS i UNION ALL SELECT256AS i ) s9
ORDER BY seq
LIMIT 400
)
tmp
WHERE
tmp.seq <=@str_length
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论