Pages

ListAgg function in Oracle SQL 12c

The LISTAGG analytic function was introduced in Oracle 11g Release 2.

the function is used to do string aggregations.

suppose I have data in employee table like this.




and we wanted display department_id and all the related employee first_name in one row , like below.


then we can use LISTAGG function to aggregate the strings.

here is the query.

select department_id,LISTAGG(first_name||',') within group (order by first_name) as Employee from EMPLOYEES
group by DEPARTMENT_ID;

Note: I have used EMPLOYEES table from HR schema in Oracle 12c.

ListAgg function in Oracle SQL 12c

The LISTAGG analytic function was introduced in Oracle 11g Release 2.

the function is used to do string aggregations.

suppose I have data in employee table like this.




and we wanted display department_id and all the related employee first_name in one row , like below.


then we can use LISTAGG function to aggregate the strings.

here is the query.

select department_id,LISTAGG(first_name||',') within group (order by first_name) as Employee from EMPLOYEES
group by DEPARTMENT_ID;

Note: I have used EMPLOYEES table from HR schema in Oracle 12c.

Featured post

Snowflake - Creating warehouse in Snowflake

Creating warehouse Login to Snowflake and click on warehouse and click on Create fill the necessary details and click Finish We can also c...