日期:2014-05-17 浏览次数:21233 次
with tab as( select 'USA,England,China,Japan' id from dual ) select substr(','||id||',',instr(','||id||',',',',1,level)+1, instr(','||id||',',',',1,level+1)-instr(','||id||',',',',1,level)-1) newid from tab connect by level <= length(','||id||',') - length(replace(','||id||',', ',', ''))-1 --10g的話,用正則表達式簡單點: with tab as( select 'USA,England,China,Japan' id from dual ) select regexp_substr(id,'[^,]+',1,level) as cl1 from tab connect by level<=length(id)-length(replace(id,',',''))+1
------解决方案--------------------
SQL> select regexp_substr('USA,England,China,Japan','[^,]+',1,level) 2 as cols 3 from dual 4 connect by 5 level<=length('USA,England,China,Japan')- 6 length(replace('USA,England,China,Japan',',',''))+1; COLS ---------------------------------------------- USA England China Japan