Animal
ID Name
1 dog
1 cat
2 Lion
How do I get the name list with the same ID? That is, you want the list of ID 1 to be dog, cat format.
1. First Oracle has a method, Wm_concat ()
Select a.ID, Wm_concat (a.name) as Namelistfrom animal Agroup by a.ID But unfortunately, this method is now out of support. 2. The second method is Xmlagg () Select a.ID, (RTrim (Xmlagg (XmlElement ("xml", a.name| | ', ') Order by a.id). Extract ('//text () '), ', ') as Nam Elistfrom animal Agroup by a.id; 3. Listagg () This method is not supported in some versions, such as My computer and school. Here is the official usage:
Select department_id "Dept.", Listagg (last_name, '; ') within group (order by Hire_date) "Employees" from Employees Group by department_id ORDER by department_id ;
Oracle multi-line connection into one row convert multiple rows to one row