1.使用条件查询 查询部门为20的员工列表
-- 查询部门为20的员工列表
SELECT t.DEPTNO,t.ENAME FROM SCOTT.EMP t where t.DEPTNO = '20' ;
效果:
2.使用 listagg() WITHIN GROUP () 将多行合并成一行
SELECT
T .DEPTNO,
listagg (T .ENAME, ',') WITHIN GROUP (ORDER BY T .ENAME) names
FROM
SCOTT.EMP T
WHERE
T .DEPTNO = '20'
GROUP BY
T .DEPTNO
效果:
3. 使用 listagg() within GROUP () over 将多行记录在一行显示
SELECT
T .DEPTNO,
listagg (T .ENAME, ',') WITHIN GROUP (ORDER BY T .ENAME) over(PARTITION BY T .DEPTNO)
FROM
SCOTT.EMP T
WHERE
T .DEPTNO = '20'
效果: