Solved

distinct in oracle xmlagg

Posted on 2011-02-24
3
3,868 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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
automatic email alert 1 52
case statement in where clause with not exist 15 52
Fastest way to replace data in Oracle 5 64
Select and Insert Query running slow 4 36
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
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.
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.

810 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