Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform SQL Rows into Comma-Separated values in Oracle [duplicate]

Tags:

sql

oracle

Possible Duplicate:
How can I combine multiple rows into a comma-delimited list in Oracle?

How can you produce a comma-separated values from list of return rows in SQL without creating a function? Need to remove duplicates and null or with 'None' as the value.

Example: select name from student;

The result :

         NAME         
        ------
        Zed
        Charlo
        None
        Charlo
        Dionn
        Ansay

Desired output :

              Name
             -------
             Zed,Charlo,Dionn,Ansay
like image 243
Ianthe Avatar asked Feb 01 '12 02:02

Ianthe


1 Answers

http://sqlfiddle.com/#!4/9ad65/2

select 
  listagg(name, ',') 
    within group (order by id) as list 
from student
like image 152
Jake Feasel Avatar answered Nov 10 '22 05:11

Jake Feasel