Friday, March 1, 2013


Very handy Listagg Function
During my daily routine, I constantly need to display multiple values for single row, I have to write a few lines of code until the LISTAGG function!
Description of listagg.gif follows
Examples from oracle
The following single-set aggregate example lists all of the employees in Department 30 in the hr.employees table, ordered by hire date and last name:
SELECT LISTAGG(last_name, '; ') WITHIN GROUP (ORDER BY hire_date, last_name) "Emp_list",
    MIN(hire_date) "Earliest"
    FROM employees
    WHERE department_id = 30;

Emp_list                                                     Earliest
------------------------------------------------------------ ---------
Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares            07-DEC-02

No comments:

Post a Comment