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) = ',' ;
經測試,以上是最快方式;利用集合處理的思想,避免了循環分割。