当前位置:Gxlcms > mysql > MYSQL分享:最快速度将字符串进行分割以表的方式进行展示_MySQL

MYSQL分享:最快速度将字符串进行分割以表的方式进行展示_MySQL

时间:2021-07-01 10:21:17 帮助过:7人阅读

bitsCN.com

MYSQL分享:最快速度将字符串进行分割以表的方式进行展示

[sql]

USE test;

CREATE TABLE test.Num ( xh INT PRIMARY KEY ); -- 创建数字辅助表

SET @i = 0;

INSERT INTO test.Num(xh) -- 写入数字辅助表

SELECT @i:=@i+1

FROM information_schema.`TABLES` a , information_schema.`TABLES` b

LIMIT 0 ,100 ;

SET @str = 'as,sbsd,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16';

SELECT SUBSTRING( str,xh, LOCATE(',',CONCAT(@str,','),xh)-xh) AS splitstr

FROM test.Num a,

( SELECT @str AS str )b

WHERE a.xh <= LENGTH( str)

AND SUBSTRING( CONCAT(',',str),xh, 1) = ',' ;

经测试,以上是最快方式;利用集合处理的思想,避免了循环分割。

bitsCN.com

人气教程排行