Oracle multi-line connection into one row convert multiple rows to one row

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.