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

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

WBOY
Release: 2016-06-01 13:33:09
Original
879 people have browsed it

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

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

     

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

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template