SQL> select * from test;
ID MC
---------- -------------
1 11111
1 22222
2 11111
2 22222
3 11111
3 22222
3 33333
已选择7行。
SQL> select id,ltrim(max(sys_connect_by_path(mc,',')),',') row2col
from (select id,mc,
id+(row_number() over(order by id)) node_id,
row_number() over(partition by id order by id) rn
from test)
start with rn = 1
connect by node_id-1 = prior node_id
group by id
order by id;
ID ROW2COL
---------- -------------------------------------------------------------
1 11111,22222
2 11111,22222
3 11111,22222,33333
SQL> select id,replace(max(sys_connect_by_path(mc,',')),',') row2col
from (select id,mc,
id+(row_number() over(order by id)) node_id,
row_number() over(partition by id order by id) rn
from test)
start with rn = 1
connect by node_id-1 = prior node_id
group by id
order by id;
ID ROW2COL
---------- ------------------------------------------------------------
1 1111122222
2 1111122222
3 111112222233333[@more@]
ID MC
---------- -------------
1 11111
1 22222
2 11111
2 22222
3 11111
3 22222
3 33333
已选择7行。
SQL> select id,ltrim(max(sys_connect_by_path(mc,',')),',') row2col
from (select id,mc,
id+(row_number() over(order by id)) node_id,
row_number() over(partition by id order by id) rn
from test)
start with rn = 1
connect by node_id-1 = prior node_id
group by id
order by id;
ID ROW2COL
---------- -------------------------------------------------------------
1 11111,22222
2 11111,22222
3 11111,22222,33333
SQL> select id,replace(max(sys_connect_by_path(mc,',')),',') row2col
from (select id,mc,
id+(row_number() over(order by id)) node_id,
row_number() over(partition by id order by id) rn
from test)
start with rn = 1
connect by node_id-1 = prior node_id
group by id
order by id;
ID ROW2COL
---------- ------------------------------------------------------------
1 1111122222
2 1111122222
3 111112222233333[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/94041/viewspace-890239/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/94041/viewspace-890239/