Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Help with SQL to concatenate row data ...
This is not an appropriate thing to do with a SQL statement. Rather it should be
done in a stored procedure.
I've no doubt someone can kludge together something to do it. But the maintainability would be near zero.
Daniel Morgan
Anti Spam wrote:
> I am hoping that someone can help me with a tip for a SQL problem that I
> have.
>
> Given an example table "MYCOLORS" which has the following 5 row entries:
>
> ID COLOR
> -- -----
> 1 VIOLET
> 1 INDIGO
> 2 BLUE
> 2 GREEN
> 2 YELLOW
> 3 ORANGE
>
> I would like to write SQL that produces the following output
>
> ID MIXED
> -- ------
> 1 VIOLET,INDIGO
> 2 BLUE,GREEN,YELLOW
> 3 ORANGE
>
> In other words, I am looking for a way to write a general SQL statement that
> aggregates the COLOR rows into single fields, grouped by the ID. Be advised
> that, beyond this example, I may not know how many different colors exist in
> the MYCOLORS table at any time.
>
> Can anyone help?
>
> Thanks,
> Charles
Received on Sun Apr 21 2002 - 04:32:48 CDT