当前位置: 代码迷 >> Oracle技术 >> oracle 施用substr对一个字符串根据逗号来分段截取
  详细解决方案

oracle 施用substr对一个字符串根据逗号来分段截取

热度:63   发布时间:2016-04-24 08:27:31.0
oracle 使用substr对一个字符串根据逗号来分段截取
有一个字符串'abc,def,mns,opq',怎么能把他同过中间的‘,’截取成4个字符串abc、def、mns和opq了?

------解决方案--------------------
select SUBSTR('abc,def,mns,opq',1,3)||'、'||SUBSTR('abc,def,mns,opq',5,7)||'、'||SUBSTR('abc,def,mns,opq',9,11)||'、'||SUBSTR('abc,def,mns,opq',13,15) FROM DUAL
------解决方案--------------------
SQL code
with t1 as (     select 1 c1,'abc,def,mns,opq' c2 from dual )select distinct c1,replace(regexp_substr(c2,'[^,]+',1,level),',',' ') c2from t1 connect by level<=length(c2)-length(replace(c2,',',''))+1order by c1     c1    c2-------------------1    1    abc2    1    def3    1    mns4    1    opq
  相关解决方案