Tuesday 10 July 2012

Query Results in Comma-Separated String

Another hidden gem.

Ever wanted to get the results of a query in a single string, with values separated by commas? e.g. you want all tables for a user to be exported using Data Pump.

Here's an easy way to get that list of tables in Data Pump-friendly format:

select wm_concat('SCOTT.'||table_name)
from dba_tables 
where owner = 'SCOTT';

Results:
SCOTT.TABLE_01,SCOTT.TABLE_02,SCOTT.TABLE_03, ...

wm_concat is an Oracle-supplied function and may change at some point in the future, etc., etc.

No comments:

Post a Comment