The most common way to merge column values is to write a custom function to the fact that this is the other way around.
The merge column values in SQL Server can use the for Xml Path, which in Oracle can use Wm_concat or Listagg.
Prepare the numbers:
CREATE TABLE MyTest (xType number,city nvarchar2),/insert into MyTest (xtype,city) SELECT 1,n ' Beijing ' from dual UNION allse Lect 1,n ' Shanghai ' from dual Union allselect 1,n ' Guangzhou ' from dual Union allselect 2,n ' Wuhan ' from dual Union allselect 2,n ' Hangzhou ' from Du Al UNION allselect 2,n ' Xiamen ' from dualcommit;/
Using Wm_concat:
SELECT Xtype,wmsys.wm_concat (To_char) as Xcityfrom Mytestgroup by XType
Using Listagg:
SELECT XType, Listagg (To_char, ', ') within GROUP (ORDER by XType) as Xcityfrom Mytestgroup by XType
Results:
XTYPE xcity
---------- --------------------------------------
1 Beijing, Guangzhou, Shanghai
2 Hangzhou, Wuhan, Xiamen
Note:
0, the above in the city before the addition of To_char () function, is to prevent the situation of the chaotic code;
1, Wm_concat in the official documents of Oracel not, can not guarantee the compatibility of each version;
2, Listagg is the 11g version of the new aggregation function.