SQL> col empnos format a40
SQL> with
2 data as (
3 select deptno, empno,
4 lag(empno) over(partition by deptno order by empno) prev_emp
5 from emp
6 )
7 select deptno,
8 substr(sys_connect_by_path(empno, ','), 2) empnos
9 from data
10 where connect_by_isleaf = 1
11 connect by prior empno = prev_emp
12 start with prev_emp is null
13 order by deptno
14 /
DEPTNO EMPNOS
---------- ----------------------------------------
10 7782,7839,7934
20 7369,7566,7788,7876,7902
30 7499,7521,7654,7698,7844,7900
Thanks to put my name and a link to this message on your blog.
Regards
Michel