Oracle10g提供了个新函数wmsys.wm_concat,可以完成行转列后列以字符串的形式进行拼接,如下SQL
- create table aaa(
- id varchar2(20)
- )
- create table bbb(
- a_id varchar2(20),
- a_name varchar2(20))
- insert into aaa values('a');
- insert into aaa values('b');
- insert into bbb values('a', '1');
- insert into bbb values('a', '2');
- insert into bbb values('a', '3');
- insert into bbb values('b', '1');
- select id, wmsys.wm_concat(b.a_name) str
- from aaa a, bbb b where a.id = b.a_id
- group by id