If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > How to Concatenate Query Output in a Nested Query

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-01-10, 09:42
Wim Venema Wim Venema is offline
Registered User
 
Join Date: Jun 2004
Location: Lichtenvoorde, Netherlands
Posts: 53
How to Concatenate Query Output in a Nested Query

Hi,

I have two tables
Table A (columns p,q)
Table B (columns r,s)

I have a nested query like:

select q, (select s from B where B.r = A.p and rownum <2) from A

Is there a way to concatenate the results (like "row1 | row2 | row3 |" etc) of the nested query to one field if there are more than one records in the nested query so I can drop the rownum < 2 part?

Regards,

Wim Venema
Reply With Quote
  #2 (permalink)  
Old 02-01-10, 10:27
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 512
Hi,

yes there are multiple ways, how to achieve this. They depend on Oracle version, you did not post.

In 11g, you may use LISTAGG function, as documented here (just follow the link for 11gR2 description).
In lower versions, you shall create auxiliary objects, like described on AskTom page here (using aggregates) or here (using function). Again, follow the links to get more details.
Reply With Quote
  #3 (permalink)  
Old 02-01-10, 20:34
artacus72 artacus72 is offline
Registered User
 
Join Date: Aug 2009
Location: Olympia, WA
Posts: 337
In 10g, you can also use wm_concat. But you won't be able to specify the separator.
Reply With Quote
  #4 (permalink)  
Old 02-03-10, 07:31
Wim Venema Wim Venema is offline
Registered User
 
Join Date: Jun 2004
Location: Lichtenvoorde, Netherlands
Posts: 53
We are running Oracle 8.1.7.4.0
The solution was from Ask Tom "Function to concatenate output"
Thank you both!!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On