select distinct regexp_substr('1,2,34,34,5', '[^,]+', 1, rownum) v1
from dual
connect by rownum <=
length('1,2,34,34,5') - length(replace('1,2,34,34,5', ',')) + 1 ;
以下實現行轉行(原創)。
即將
1 aa,bb,cc
2 cc,dd
轉成
1 aa
1 bb
1 cc
2 cc
2 dd
create table temp ( a number(10) , b varchar2(300)) ;
insert into temp values( 101, '111,233,443,988328,000,23,k34');
insert into temp values( 777, '1k,88u,99ie,88j');
with temp_1 as
(select a, length(a.b) - length(replace(a.b, ',')) + 1 numbs from temp a)
select t4.a,(
select regexp_substr(tt.b, '[^,]+', 1, t4.flg)
from temp tt
where tt.a = t4.a)
from(
select t2.a, t2.numbs, sum(1) over(partition by t2.a, t2.numbs
order by t3.r) flg
from(
select t1.a, t1.numbs, t1.ed - t1.numbs + 1 st, t1.ed
from(
select t.a, t.numbs, sum(t.numbs) over(
order by t.a) ed
from temp_1 t) t1) t2,(
select rownum r
from dual a
connect by rownum <= (
select sum(numbs)
from temp_1)) t3
where r >= st and r <= ed) t4;
good article:
http://www.cnblogs.com/killkill/archive/2010/09/06/1819536.html
http://wang11qiang11.blog.163.com/blog/static/980301092010223105737592/