Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle 11i  pl/sql

Posted on 2011-09-28
4
Medium Priority
?
297 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 78

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 78

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

916 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