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

Home -> Community -> Usenet -> c.d.o.misc -> Re: put all the sub-elements for a particular element next to the element on one line

Re: put all the sub-elements for a particular element next to the element on one line

From: Michel Cadot <micadot_at_netcourrier.com>
Date: Thu, 9 Dec 1999 11:26:54 +0100
Message-ID: <82o09v$13m8n$1@oceanite.cybercable.fr>


you can do it with a function:

create or replace function f(id varchar2) return varchar is

   result varchar2(32000) := '';
   cursor curs is select ColumnB from TableA where ColumnA = id;    first boolean := true;
begin

   for rec in curs loop

      if first then
         result := rec.ColumnB;
         first := false;
      else
         result := result || ' ' || rec.ColumnB;
      end if;

   end loop;
   return result;
end;
/

then
select ColumnA, f(ColumnA) from TableA group by ColumnA;

--
Have a nice day
Michel

Robert Moldenhauer <persia_at_persia.com> a écrit dans le message : 384DB20C.C0061C41_at_persia.com...
> If I have a table structured in the following way:
>
> TableA
>
> ColumnA | ColumnB
> Cat Ferrari
> Cat Holden
> Cat Ford
> Cat Toyota
>
> What Oracle computer code SQL or PL/SQL would twist the data so it would
>
> display in the following way:
>
> Cat Ferrari Holden Ford Toyota
>
> Essentially what I am trying to do is to put all the sub-elements for a
> particular element next to the element on one line by extending the
> following code:
>
> select ColumnA, ColumnB from TableA where ColumnA = 'Cat';
>
>
>
>
Received on Thu Dec 09 1999 - 04:26:54 CST

Original text of this message

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