Thursday, March 26, 2015

Aggregate columns in multiple rows into a single column in Oracle

To aggregate columns in multiple rows into a single column in Oracle,

use `LISTAGG` function as follows:

SELECT LISTAGG(id, ',') WITHIN GROUP (ORDER BY id) FROM tb_person WHERE first_name = 'Johnny';

Reference:
https://docs.oracle.com/database/121/SQLRF/functions100.htm#SQLRF30030

No comments:

Post a Comment