Solved

distinct in oracle xmlagg

Posted on 2011-02-24
3
3,581 Views
Last Modified: 2012-05-11
Experts.. I have a query which is below

 select rtrim(EXTRACT(XMLAGG (XMLELEMENT("s",a.src_id|| ',' )), '/s/text()').getstringval())
        into v_src_id_list
        from cfs a, cdr b
        where b.emp_oid = 235
        and b.enty_id= a.enty_id;

This is getting the list but some of the elements in the list are duplicates. for ex: when I print out the v_src_id_list I have 1,2,3,3,4,4,5 in it.

Is there any way to eliminate the duplicates in this list?
0
Comment
Question by:chickanna
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 34973670
Check out:
http://www.experts-exchange.com/Database/Oracle/Q_26845549.html


Try this:
select rtrim(EXTRACT(XMLAGG (XMLELEMENT("s",src_id|| ',' )), '/s/text()').getstringval())
        into v_src_id_list
        from ( select distinct a.src_id from cfs a, cdr b
        where b.emp_oid = 235
        and b.enty_id= a.enty_id);

0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 250 total points
ID: 34973673
query distinct values first then aggregate


 select rtrim(EXTRACT(XMLAGG (XMLELEMENT("s",src_id|| ',' )), '/s/text()').getstringval())
        into v_src_id_list
from
(select distinct a.src_id
        from cfs a, cdr b
        where b.emp_oid = 235
        and b.enty_id= a.enty_id)

0
 

Author Closing Comment

by:chickanna
ID: 34973785
thank you experts.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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 shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now