SQL output related query .merging five values in a column into a single value separated by comma

My input is in the below form:

select a.ab from tableone a ;

Result :

aa
bb
cc

Desired output:

('aa','bb','cc') 

Upvotes: 0

Views: 18

Answers (1)

Littlefoot
Littlefoot

Reputation: 142720

Use LISTAGG function.

Table contents:

SQL> select ab from tableone;

AB
--
aa
bb
cc

Result you need:

SQL> select '(' || listagg(chr(39) || ab || chr(39), ',') within group (order by ab) || ')' result from tableone;

RESULT
--------------------------------------------------------------------------------
('aa','bb','cc')

SQL>

Upvotes: 1

Related Questions