Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: concatenate the same column with mulitple rows
On Nov 30, 11:33 pm, sheridany <sherid..._at_yahoo.com> wrote:
> I have an oracle database that has text values (comments) in
> subsequent rows and I need to add them all together by the primary
> key.
>
> primary key text_field
> 1111 I like Oracle
> 1111 It is fast
> 1111 Their support is great!
> 2222 Oracle is hard
>
> The data would look like this in the result set. We cannot create
> tables on this db so we only have read access.
>
> 1111 I like Oracle It is fast Their support is great!
> 2222 Oracle is hard
What you want is called a pivot table. There are several possible approaches. Here is one from the archives:
If the link does not work go to http://groups.google.com and use advanced search on comp.databases.oracle.* for "pivot table". You will find many threads. Billy Verreynne has posted a couple of solutions.
You can also use user written aggregiate functions (see http://asktom.oracle.com) and I have used the analytic function row_number to help pivot rows into columns which I just concatenated together.
HTH -- Mark D Powell -- Received on Sat Dec 01 2007 - 09:07:33 CST