Return-Path: <ml-errors@fatcity.com>
Received: from ensim.rackshack.net (root@localhost)
 by orafaq.net (8.11.6/8.11.6) with ESMTP id h8Q0OYK05691
 for <oracle-l@orafaq.net>; Thu, 25 Sep 2003 19:24:34 -0500
X-ClientAddr: 66.27.56.212
Received: from www3.fatcity.com (rrcs-west-66-27-56-212.biz.rr.com [66.27.56.212])
 by ensim.rackshack.net (8.11.6/8.11.6) with ESMTP id h8Q0OYc05686
 for <oracle-l@orafaq.net>; Thu, 25 Sep 2003 19:24:34 -0500
Received: (from root@localhost)
 by www3.fatcity.com (8.11.6/8.11.6) id h8PL0Xu09171
 for oracle-l@orafaq.net; Thu, 25 Sep 2003 14:00:33 -0700
Received: by fatcity.com (05-Jun-2003/v1.0g-b73/bab) via fatcity.com id 005D114E; Thu, 25 Sep 2003 13:59:43 -0800
Message-ID: <F001.005D114E.20030925135943@fatcity.com>
Date: Thu, 25 Sep 2003 13:59:43 -0800
To: Multiple recipients of list ORACLE-L <ORACLE-L@fatcity.com>
X-Comment: Oracle RDBMS Community Forum
X-Sender: sundeep maini <sundeep_maini@yahoo.com>
Sender: ml-errors@fatcity.com
Reply-To: ORACLE-L@fatcity.com
Errors-To: ML-ERRORS@fatcity.com
From: sundeep maini <sundeep_maini@yahoo.com>
Subject: Re: SQL Query
Organization: Fat City Network Services, San Diego, California
X-ListServer: v1.0g, build 73; ListGuru (c) 1996-2003 Bruce A. Bergman
Precedence: bulk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Mike,

Just wanted to supplement your example with another one from my
environment:

SELECT c.customer_id
      ,customer_name
      ,utils.code_table_to_string(CAST( MULTISET(
        SELECT distinct dlr_dealer_code
          FROM dealer_customers dc
		       ,dlr_dealer_master_t
         WHERE dc.customer_id = dc_in.customer_id
		   AND dlr_dealer_id = dc.dealer_id
		 ORDER BY dlr_dealer_code
		) AS code_table_t
	  )) spans_these_dealers
 FROM customers c
     ,(
       SELECT customer_id
	     FROM dealer_customers 
		GROUP BY customer_id
		HAVING COUNT(distinct dealer_id) > 1
	  ) dc_in
WHERE dc_in.customer_id = c.customer_id;


Does eseentially the same thing. In this case it concatenates the
dealer_codes per customer (identifies customers spanning multiple
dealers) on the same row.  Here is a sample of the output:

2969473096	Mountain Enterprises Inc	D100,D470,D480
2969473121	K C Construction	B010,B150,B190
2969473195	GOODFELLOW BROS	H140,H330

--- Mike Spalinger <Michael.Spalinger@Sun.COM> wrote:
> Imran,
> 
> Tom Kyte has a thread that might help:
>
http://asktom.oracle.com/pls/ask/f?p=4950:8:1554835115460038644::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:229614022562,
> 
> Essentially, you can do this:
> 
> CREATE or replace FUNCTION CONCAT_LIST( cur SYS_REFCURSOR )
>    RETURN  VARCHAR2 IS
>      ret VARCHAR2(32000);
>      tmp VARCHAR2(4000);
> BEGIN
>      loop
>          fetch cur into tmp;
>          exit when cur%NOTFOUND;
>              ret := ret || ' ' || tmp;
>      end loop;
>      RETURN ret;
> END;
> /
> 
> SQL> select * from mike;
> 
>          ID TEXT             ORDR
> ---------- ---------- ----------
>           1 B                   2
>           1 A                   1
>           1 C                   3
> 
> SELECT id, SUBSTR(CONCAT_LIST(CURSOR(
>     SELECT text
>        FROM (select id, text, ordr from mike order by ordr) ee
>        WHERE e.id = ee.id)),1,40) list
> FROM ( select distinct id from mike) e;
> 
>          ID LIST
> ---------- --------------------
>           1  A B C
> 
> Mike
> 
> 
> Imran Ashraf wrote:
> > Hi,
> > 
> > I have the following data , table Temp
> > 
> > ID  Text   Order
> > 1     B        2
> > 1     A        1
> > 1     C        3
> > 
> > 
> > I want to write a query which says: wherever there is more than 1
> occurrence
> > of ID then  concatenate the text in the order specified in the
> order column.
> > So i would get:
> > 
> > ID  Text
> > 1     A B C
> > 
> > Any suggestions?
> > 
> > Thanks
> > 
> > Imran
> 
> 
> -- 
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> -- 
> Author: Mike Spalinger
>   INET: Michael.Spalinger@Sun.COM
> 
> Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
> San Diego, California        -- Mailing list and web hosting
> services
>
---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from).  You may
> also send the HELP command for other information (like
subscribing).


=====

Sundeep Maini 
Consultant 
Currently on Assignement at Caterpillar Peoria
sundeep_maini_k@cat.com 

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: sundeep maini
  INET: sundeep_maini@yahoo.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

