dbTalk Databases Forums  

string concatenation via Group By

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss string concatenation via Group By in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
dn.perl@gmail.com
 
Posts: n/a

Default string concatenation via Group By - 01-26-2010 , 11:07 AM






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.

Reply With Quote
  #2  
Old   
Michel Cadot
 
Posts: n/a

Default Re: string concatenation via Group By - 01-26-2010 , 11:33 AM






<dn.perl (AT) gmail (DOT) com> a écrit dans le message de news: a122dd75-b1d1-40cb-ac85-fdfb42510376...oglegroups.com...
Quote:
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.

Yes, using T. Kyte's STRAGG function or WM_CONCAT one.

Regards
Michel

Reply With Quote
  #3  
Old   
Shakespeare
 
Posts: n/a

Default Re: string concatenation via Group By - 01-26-2010 , 02:43 PM



Op 26-1-2010 17:07, dn.perl (AT) gmail (DOT) com schreef:
Quote:
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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.