Solved

Oracle 11i  pl/sql

Posted on 2011-09-28
4
288 Views
Last Modified: 2012-08-13
Hello,

I need to have a result set that is pipe separated - Is this something that I can write just in a query or will I need to actually loop through the result set and create it.
For example results are:
1
2
3
I want only one return  that looks like this:  1 || 2 || 3
0
Comment
Question by:Mosquitoe
  • 2
  • 2
4 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36719060
Try this:

http://www.experts-exchange.com/Database/Oracle/Q_24914739.html?#a25864822

SELECT
       RTRIM(
           EXTRACT(XMLAGG(XMLELEMENT("s", yourtable.column3 || '||')), '/s/text()').getstringval(),
           '||'
       )
           column3
FROM yourtable
;
0
 

Author Comment

by:Mosquitoe
ID: 36719119
I keep getting an error on this (I had tried to use the listagg function as well - but same error)  Keeps telling me I am missing left parenthesis but I must be blind because I cannots ee what i am missing:

SELECT
       RTRIM(
           EXTRACT(XMLAGG(XMLELEMENT("s", dossier_waste_packaging dwp.dwp.packaging_types || '||')), '/s/text()').getstringval(),
           '||'
       )
           dwp.packaging_types
FROM dossier_waste_packaging dwp
      WHERE dwp.dos_hwmd_sys_entered_yr = 10
      AND dwp.dossier_identifier = 325
      AND dwp.dossier_type_code = 'EXP';
0
 

Author Comment

by:Mosquitoe
ID: 36719130
I tried this as well:

SELECT DISTINCT LISTAGG(dwp.packaging_types, '||') WITHIN GROUP AS PackagingList
      FROM dossier_waste_packaging dwp
      WHERE dwp.dos_hwmd_sys_entered_yr = 10
      AND dwp.dossier_identifier = 325
      AND dwp.dossier_type_code = 'EXP
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 125 total points
ID: 36719174
I keep forgetting about listagg.


Try this:
...
LISTAGG(dwp.packaging_types, '||') WITHIN GROUP (order by packaging_types) AS PackagingList
...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question