拆分MySql中的字符串 [英] Split the string in MySql

查看:70
本文介绍了拆分MySql中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...



我想通过MYSQL查询从MySQL数据库中分割数据,下表视图很容易理解我想要的...



客户表:



Hi all...

I want MYSQL query for split the data from MySQL database, the following table view is easy to understand what i want...

client table:

----------------------
s.no  |  batch
----------------------
1     |  1@ravi@1991
2     |  2@kumar@1990
3     |  3@raj@1989
----------------------



here 1 @ ravi @ 1991



1 =客户ID

ravi =客户名称

1991 =客户DOB。

现在我想显示如下的详细信息


here 1@ravi@1991

1=client id
ravi=client name
1991=client DOB.
Now i want display the details like below

-------------------------
s.no  |  id | name | DOB
-------------------------
1     |  1 |ravi  |1991
2     |  2 |kumar |1990
3     |  3 |raj   |1989
-------------------------





请发送您的想法....



pls send your ideas....

推荐答案

您可以使用< a href =http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring> SUBSTRING_INDEX(str,delim,count) [ ^ ]。



第一个值:
You can use SUBSTRING_INDEX(str,delim,count)[^] for this.

First value:
SUBSTRING_INDEX( batch, '@', 1 )



第二个值:


Second value:

SUBSTRING_INDEX( SUBSTRING_INDEX( batch, '@', -2 ), '@', 1 )



第三个值:


Third value:

SUBSTRING_INDEX( batch, '@', -1 )





我没有对此进行过测试,但根据文档可以使用。



I have not tested this, but based on the documentation this should work.


解决方案在这里::

Solution is here::
select SUBSTRING_INDEX(batch,'@',1) as id,
SUBSTRING_INDEX( SUBSTRING_INDEX( batch, '@', -2 ), '@', 1 ) as name,
SUBSTRING_INDEX( batch, '@', -1 ) as DOB
from stock;





感谢Andre kraak ......



Thank for Andre kraak...


这篇关于拆分MySql中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆