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

Home -> Community -> Usenet -> c.d.o.server -> Re: how to condense several rows of a select?

Re: how to condense several rows of a select?

From: Matt Gay <invisiblelizard_at_worldnet.att.net>
Date: Sat, 03 Feb 2001 04:05:58 GMT
Message-ID: <3A7B8429.20D2A129@worldnet.att.net>

Have you tried PL/SQL for this? I'm thinking it's the best way. (It's been a while so forgive me if my syntax is a bit rough.)

DECLARE
    x char;
    y char;
    z char := ' ';
    cursor test1 is select col1, col2 from tablename; BEGIN
    dbms_output.enable;
    open test1;
    loop;
    fetch test1 into x, y;
    exit when test1%notfound;
    if x != z then

        x := z;
        dbms_output.new_line;
        dbms_output.put (x||' '||y);
    else
        dbms_output.put (', '||y);

    end if;
    end loop;
END;
/

Something like that? What do you think?

Matt

sp wrote:

> I want to condense several rows of a select.
> mytable :
> 1 a
> 2 b
> 2 c
> 2 d
> 3 a
>
> so that my select should result in
>
> 1 a
> 2 b,c,d
> 3 a
>
> Any idea to achieve this result?
> SP
Received on Fri Feb 02 2001 - 22:05:58 CST

Original text of this message

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