Aggregate Rows in Oracle SQL Expression
2 answers
If you have 11g Release 2 you can use Listagg
:
Select a, Listagg(b, ', ') Within Group ( Order By b )
From t
Group By a
It allows you to sort your values, and it already ships with Oracle:
A1 B1, B2, B3
A2 B1, B4
Otherwise, you can use stragg
Tom Kyte's feature described in Lines per Line .
Select a, stragg(b)
From t
Group By a
returns
A1 B1,B3,B2
A2 B1,B4
+3
a source to share