日期:2014-05-17 浏览次数:20851 次
with test as ( select 'aaa' a,'1,2,3' c from dual union all select 'bbb' a,'1,2' c from dual ) select a,substr(t.ca,instr(t.ca, ',', 1, c.lv) + 1,instr(t.ca, ',', 1, c.lv + 1) -(instr(t.ca, ',', 1, c.lv) + 1)) AS c from (select a,',' || c || ',' AS ca,length(c || ',') - nvl(length(REPLACE(c, ',')), 0) AS cnt FROM test)t, (select LEVEL lv from dual CONNECT BY LEVEL <= 100) c where c.lv <= t.cnt order by a a c --------------------- 1 aaa 1 2 aaa 2 3 aaa 3 4 bbb 2 5 bbb 1
------解决方案--------------------
with t as( select 'a,b,c,d' str from dual ) SELECT regexp_substr(str, '[^,]+', 1, level) from t connect by level <= length(str) - length(replace(str, ',', '')) + 1; REGEXP_SUBSTR(STR,'[^,]+',1,LE ------------------------------ a b c d
------解决方案--------------------
select regexp_substr(values, '[^,]+',1,levle)
from t
connect by level <= length(values) - length(replace(values,',','')) + 1