Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Returning multiple rows as a single row

RE: Returning multiple rows as a single row

From: Guidry, Chris <chris.guidry_at_atcoelectric.com>
Date: Tue, 22 Jan 2002 10:47:48 -0800
Message-ID: <F001.003F7756.20020122102005@fatcity.com>

Will this suit your needs?

SET SERVEROUTPUT ON FORMAT WRAPPED SIZE 1000000 DECLARE   CURSOR c1 IS
    SELECT custid, software
    FROM customer_software
    ORDER BY custid;

  id            NUMBER;
  sw            VARCHAR2(15);
  output                VARCHAR2(100);
  temp_id       NUMBER;
  temp_sw       VARCHAR2(15);

BEGIN
  OPEN c1;
  FETCH c1 INTO id, sw;
  output := id||' '||sw;
  temp_id := id;
  temp_sw := sw;
  LOOP
    FETCH c1 INTO id, sw;
    EXIT WHEN c1%NOTFOUND;
    IF (id = temp_id) THEN
      output := output||' '||sw;
    ELSE

      DBMS_OUTPUT.PUT_LINE(output);
      output := id||' '||sw;

    END IF;
    temp_id := id;
    temp_sw := sw;
  END LOOP;
  output := id||' '||sw;
  DBMS_OUTPUT.PUT_LINE(output);
  CLOSE c1;
END;
/
--
Chris J. Guidry  P.Eng.
ATCO Electric, Metering Services
Phone: (780) 420-4142
Fax: (780) 420-3854
Email: chris.guidry_at_atcoelectric.com



> -----Original Message-----
> From: Dave Morgan [SMTP:dave.morgan_at_cybersurf.net]
> Sent: Monday, January 21, 2002 02:35 PM
> To: Multiple recipients of list ORACLE-L
> Subject: Returning multiple rows as a single row
>
> Hi All,
> I know I've seen this before but I forget ...
> Given a table like
>
> Customer_Software(
> Custid Number
> Software Varchar
> )
>
> How do I return the customerid and all the software entries in a single
> row?
> Desired output is like
>
> Custid
> --------------------------------------
> 1 Excel Word StarOffice
> 2 vi tgif oracle
> ...
>
> I know it's a group by with a subquery but ....
>
>
> TIA
> Dave
> --
> Dave Morgan
> DBA, Cybersurf
> Office: 403 777 2000 ext 284
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: Dave Morgan
> INET: dave.morgan_at_cybersurf.net
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_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).
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Guidry, Chris INET: chris.guidry_at_atcoelectric.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_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).
Received on Tue Jan 22 2002 - 12:47:48 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US