Reputation: 458
I need make a query that I get the result and put in one line separated per comma.
For example, I have this query:
SELECT
SIGLA
FROM
LANGUAGES
This query return the result below:
SIGLA
ESP
EN
BRA
I need to get this result in one single line that way:
SIGLA
ESP,EN,BRA
Can anyone help me?
Thank you!
Upvotes: 0
Views: 6854
Reputation: 167842
If you want to get the values grouped together in the order that Oracle produces the rows then:
SELECT LISTAGG( SIGLA, ',' ) WITHIN GROUP ( ORDER BY ROWNUM ) AS SIGLA
FROM LANGUAGES;
If you want alphabetical ordering then replace ORDER BY ROWNUM
with ORDER BY SIGLA
(or, curiously, ORDER BY NULL
).
Upvotes: 1
Reputation: 1718
try
SELECT LISTAGG( SIGLA, ',' ) within group (order by SIGLA) as NewSigla FROM LANGUAGES
Upvotes: 1
Reputation: 1625
SELECT LISTAGG(SIGLA, ', ') WITHIN GROUP (ORDER BY SIGLA) " As "S_List" FROM LANGUAGES
Should be the listagg sequence you are needing
Upvotes: 2