Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Oracle 11i  pl/sql

Posted on 2011-09-28
4
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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…
This video shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

722 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