11gR2 - LISTAGG
11gR2中提供了行列转换的函数–。可以实现如下功能。
SQL> SELECT deptno, LISTAGG(ename, ‘; ‘) WITHIN GROUP (order by ename) as
2 emp_list FROM emp GROUP BY deptno;DEPTNO EMP_LIST
———- ———————————————————————-
10 CLARK; KING; MILLER
20 ADAMS; FORD; JONES; SCOTT; SMITH
30 ALLEN; BLAKE; JAMES; MARTIN; TURNER; WARD
这个功能在10g和9i中要通过等方法实现。
For a specified measure,
LISTAGGorders data within each group specified in theORDERBYclause and then concatenates the values of the <measure> column.
- As a single-set aggregate function,
LISTAGGoperates on all rows and returns a single output row.- As a group-set aggregate, the function operates on and returns an output row for each group defined by the
GROUPBYclause.- As an analytic function,
LISTAGGpartitions the query result set into groups based on one or more expression in thequery_partition_clause.