Solved

distinct in oracle xmlagg

Posted on 2011-02-24
3
4,184 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
[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
3 Comments
 
LVL 77

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 74

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

Technology Partners: 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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
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

734 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