码迷,mamicode.com
首页 > 其他好文 > 详细

6.14 提取第n个分割的子串

时间:2017-09-14 23:41:09      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:分割   sele   from   问题   ace   字符串   select   replace   string   

问题:从字符串中提取出一个指定的、由分割符隔开的子字符串。
create view v as 
select ‘mo,larry,curly‘ as name
from t1
union all
select ‘tina,gina,jaunita,regina,leena‘ as name from t1;

select * from v;
+--------------------------------+
| name                           |
+--------------------------------+
| mo,larry,curly                 |
| tina,gina,jaunita,regina,leena |
+--------------------------------+

 

解决方案:

select name 
from (
select iter.pos,
substring_index(
substring_index(src.name,‘,‘,iter.pos),‘,‘,-1) name 
from v src,
(select id pos from t10) iter 
where iter.pos <=
length(src.name)-length(replace(src.name,‘,‘,‘‘))
)x 
where pos =2;

+-------+
| name  |
+-------+
| larry |
| gina  |
+-------+

6.14 提取第n个分割的子串

标签:分割   sele   from   问题   ace   字符串   select   replace   string   

原文地址:http://www.cnblogs.com/liang545621/p/7523198.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!