Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: how to condense several rows of a select?
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);
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