How can I concatenate column data into string separated by ","?

102 Views Asked by At

I have data like this

ATTRIBUTE_NAME
--------------
Area
Branch
Sector
Data Line

and I need to get data like this

Area","Branch","Sector","Data Line

OR

"Area","Branch","Sector","Data Line"

or something simpler. I have tried:

  • WM_CONCAT but I'm not able to specify the separator
  • LISTAGG is not supported in my Oracle version
  • SYS_CONNECT_BY_PATH I'm not sure how to use

I am using Oracle 11.1.0.6

1

There are 1 best solutions below

0
On

Just concatenate the extra separators onto the column before the aggregation:

select wm_concat('"' || attribute_name || '"')
  from my_table

You should note that WM_CONCAT() is an unsupported function and it would be better to upgrade your database to at least 11.2 (if not 12) to take advantage of the increased functionality.