Re: string concatenation via Group By
From: Shakespeare <whatsin_at_xs4all.nl>
Date: Tue, 26 Jan 2010 20:43:54 +0100
Message-ID: <4b5f45f7$0$22933$e4fe514c_at_news.xs4all.nl>
Op 26-1-2010 17:07, dn.perl_at_gmail.com schreef:
>
> Is it possible to concatenate records in a field via Group By clause
> of an SQL statement?
>
> Untested script is :
> create table t1(country varchar2(32), state varchar2(32), city varchar2
> (32)) ;
> insert into t1 values ('USA', 'CA', 'Sacramento') ;
> insert into t1 values ('USA', 'CA', 'San Jose') ;
> insert into t1 values ('USA', 'CA', 'three') ;
> insert into t1 values ('USA', 'CA', 'four') ;
> insert into t1 values ('USA', 'CA', 'Fremont') ;
> insert into t1 values ('Canada', 'OT', 'Ottawa') ;
> insert into t1 values ('Canada', 'OT', 'Toronto') ;
>
> Expected output for the SQL statement would be :
> USA CA Sacramento, San Jose, three, four, Fremont
> Canada OT Ottawa, Toronto
>
>
> Thanks in advance.
>
Date: Tue, 26 Jan 2010 20:43:54 +0100
Message-ID: <4b5f45f7$0$22933$e4fe514c_at_news.xs4all.nl>
Op 26-1-2010 17:07, dn.perl_at_gmail.com schreef:
>
> Is it possible to concatenate records in a field via Group By clause
> of an SQL statement?
>
> Untested script is :
> create table t1(country varchar2(32), state varchar2(32), city varchar2
> (32)) ;
> insert into t1 values ('USA', 'CA', 'Sacramento') ;
> insert into t1 values ('USA', 'CA', 'San Jose') ;
> insert into t1 values ('USA', 'CA', 'three') ;
> insert into t1 values ('USA', 'CA', 'four') ;
> insert into t1 values ('USA', 'CA', 'Fremont') ;
> insert into t1 values ('Canada', 'OT', 'Ottawa') ;
> insert into t1 values ('Canada', 'OT', 'Toronto') ;
>
> Expected output for the SQL statement would be :
> USA CA Sacramento, San Jose, three, four, Fremont
> Canada OT Ottawa, Toronto
>
>
> Thanks in advance.
>
11g has a LISTAGG function for this!
Shakespeare Received on Tue Jan 26 2010 - 13:43:54 CST