需要用wm_concat函数来实现。 如目前在emp表中查询数据如下: 要按照deptno相同的将ename以字符串形式合并,可用如下语句: select deptno,wm_concat(ename) from emp group by deptno;查询结果:
ぃ伊丽莎白鼠
2024-04-11 04:30:25
create table test (id int, name varchar(10) ) insert into test values (1,'a') insert into test values (1,'b') insert into test values (1,'c') insert into test values (2,'a') insert into test values (2,'b') insert into test values (3,'a') insert into test values (3,'c') select id,sys_connect_by_path(name,',') from ( select id,name, row_number() over(partition by id order by name)rn, count(*) over(partition by id ) cnt from test ) a where level=cnt start with rn=1 connect by prior id=id and prior rn=rn-1 测试后 可用。 一楼的回答其实最容易理解了。你把它修改成动态sql 就可以了。可以不受限制了。