Oracle columns of multiple rows of data are spelled into a single line of characters

Source: Internet
Author: User

Oracle columns of multiple rows of data are spelled into a single line of characters

 oracle provides two functions Wmsys.wm_concat and Listagg functions.    www.2cto.com   First Introduction: wmsys.wm_concat Example:        ID  name        1   aa        2   bb        3   cc  knot The fruit is "aa,bb,cc"  select Wmsys. Wm_concat (a.name) from User A In this case, the query results: "AA,BB,CC"    www.2cto.com   delimiter If you do not need to use the English comma, you need to change to other symbols such as semicolons, You can replace it with the following method: Select Replace (Wmsys. Wm_concat (A.name), ', ', '; ') from User a result: "AA;BB;CC" ============================================================== The syntax structure of the ========LISTAGG function   Listagg function is as follows:   listagg ([,]) within GROUP (ORDER by) [Over (PARTITION by)]    Listagg is an aggregation function, but it can provide analysis functionality (such as an optional over () clause). With Listagg, the elements in the following are required:  www.2cto.com   The column or expression that needs to be aggregated   with Group keyword   group ORDER BY clause example:   deptno ename-------------------       10 clark       10 king    & nbsp  10 MILLER&NBSp      20 adams       20 ford       20 Jones Group by Deptno field, string aggregation of result sets , the results are as follows: DEPTNO aggregated_enames----------------------------------    clark,king,miller    20 Adams,ford,jonessql:select Deptno,listagg (ename, ', ') within group (ORDER by ename) as employees from  emp GROUP by D Eptno;

Multiple rows of data in an Oracle column are spelled in one line of characters

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.