Oracle - SQL to concatenate multiple rows -
this question has answer here:
let’ have table 3 columns
id integer, offset integer, str varchar(50)
containing values:
id offset str 1 1 teststr1 1 2 teststr3 1 3 teststr5 2 1 teststr4 2 2 teststr2 3 1 teststr6
i pull concatenated “str” each id (ordered offset). basically, want is:
id str 1 teststr1teststr3teststr5 2 teststr4teststr2 3 teststr6
any thoughts on how construct similar query?
if have oracle 11g use listagg() function this:
select id , listagg(str) within group (order offset) str_of_str yourtable group id
see: http://docs.oracle.com/cd/e11882_01/server.112/e10592/functions089.htm , this sqlfiddle
| id | str_of_str | |----|--------------------------| | 1 | teststr1teststr3teststr5 | | 2 | teststr4teststr2 | | 3 | teststr6 |
Comments
Post a Comment