Oracle wmsys. wm_concat function usage

Source: Internet
Author: User

Oracle wmsys. wm_concat function, which uses the ',' link character.

Example:

SQL> Create Table idtable (ID number, name varchar2 (30 ));

Table created

SQL> insert into idtable values (10, 'AB ');

1 row inserted

SQL> insert into idtable values (10, 'bc ');

1 row inserted

SQL> insert into idtable values (10, 'cd ');

1 row inserted

SQL> insert into idtable values (20, 'Hi ');

1 row inserted

SQL> insert into idtable values (20, 'ij ');

1 row inserted
SQL> insert into idtable values (20, 'mn ');

1 row inserted

SQL> select * From idtable;

ID name
----------------------------------------
10 AB
10 BC
10 cd
20 hi
20 IJ
20 mN

6 rows selected
SQL> select ID, wmsys. wm_concat (name) name from idtable
2 group by ID;

ID name
------------------------------------------------------------------------------------------
10 AB, BC, CD
20 hi, IJ, Mn

SQL> select ID, wmsys. wm_concat (name) over (order by ID) name from idtable;

ID name
------------------------------------------------------------------------------------------
10 AB, BC, CD
10 AB, BC, CD
10 AB, BC, CD
20 AB, BC, CD, hi, IJ, Mn
20 AB, BC, CD, hi, IJ, Mn
20 AB, BC, CD, hi, IJ, Mn

6 rows selected

SQL> select ID, wmsys. wm_concat (name) over (order by ID, name) name from idtable;

ID name
------------------------------------------------------------------------------------------
10 AB
10 AB, BC
10 AB, BC, CD
20 AB, BC, CD, hi
20 AB, BC, CD, hi, IJ
20 AB, BC, CD, hi, IJ, Mn

6 rows selected

I personally think this usage is interesting.

SQL> select ID, wmsys. wm_concat (name) over (partition by ID) name from idtable;

ID name
------------------------------------------------------------------------------------------
10 AB, BC, CD
10 AB, BC, CD
10 AB, BC, CD
20 hi, IJ, Mn
20 hi, IJ, Mn
20 hi, IJ, Mn

6 rows selected

SQL> select ID, wmsys. wm_concat (name) over (partition by ID, name) name from idtable;

ID name
------------------------------------------------------------------------------------------
10 AB
10 BC
10 cd
20 hi
20 IJ
20 mN

6 rows selected

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.