LISTAGG
is a string aggregation function that concatenates values from multiple rows into a single, comma-separated string (or with a custom delimiter).LISTAGG(column_name, 'delimiter') WITHIN GROUP (ORDER BY column_name);
========================================================================
SELECT LISTAGG(city, ', ') WITHIN GROUP (ORDER BY city desc ) "CIty_Listing" FROM emp1;
- vijayawada, vijayawada, vijayawada, vijayawada, hyd, hyd, hyd, hyd, hyd, hyd, hyd, hyd, hyd, hyd, bangalore, bangalore, OMAN
========================================================================
SELECT dept_name, LISTAGG(first_name, '-') WITHIN GROUP(ORDER BY first_name ) AS employees
FROM emp1
GROUP BY dept_name
ORDER BY dept_name;
- developer ALBERT-RAJA-SANDEEP
- progammar MOHAN
- programmar DIVYA_GN-DIVYA_GN-PRABHU_GN-divya_GN-divya_GN-divya_GN-divya_GN-divya_GN
- tester AKHIL-AYYAPPA_GN-MAHESH_GN-SUNNY
========================================================================