参考这个:select deptno, ltrim(MAX(sys_connect_by_path(ename, ',')), ',') str from (select ename, deptno, row_number() over(partition by deptno order by ename) rn from emp) t start with rn = 1 connect by prior rn = rn - 1 and prior deptno = deptno group by deptno
A 2
A 3
B 4
C 5
C 6
D
变成
A 1,2,3
B 4
C 5,6
D
这个样子上面乱掉了
from (select ename,
deptno,
row_number() over(partition by deptno order by ename) rn
from emp) t
start with rn = 1
connect by prior rn = rn - 1
and prior deptno = deptno
group by deptno