Get a delimited list in Oracle SQL


There are many times that I need to retrieve a delimited list in SQL and every time I have to track the solution down.

 

So here it is.

SELECT RTRIM (
 rtrim(XMLAGG (XMLELEMENT (e, column_name || ',')).EXTRACT ('//text()'), ',') name
 FROM table_name;

 

Just to break this down a little

rtrim(XMLELEMENT (e, column_name || 'This is the delimiter')).EXTRACT 
('//text()'), 'This is the delimiter')



Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s