Oracle listparts deduplication method, oraclelistparts deduplication

Source: Internet
Author: User

Oracle listparts deduplication method, oraclelistparts deduplication
1. Use a regular expression to remove duplicates

SELECT regexp_replace('2,2,3,4,5 ', '([^,]+)(,\1)+', '\1') AS col  FROM dual
Query results:

SQL> SELECT regexp_replace('2,2,3,4,5 ', '([^,]+)(,\1)+', '\1') AS col  2    FROM dual  3  ; COL--------2,3,4,5
You can sort strings by weight.


2. Use the regular expression above to weight the listparts.

SELECT listagg(t.deptno, ',') within GROUP(ORDER BY t.deptno) deptno,       regexp_replace((listagg(t.deptno, ',') within GROUP(ORDER BY t.deptno)), '([^,]+)(,\1)+', '\1') bl_number  FROM scott.emp t
Execution result:

SQL> SELECT listagg(t.deptno, ',') within GROUP(ORDER BY t.deptno) deptno,  2         regexp_replace((listagg(t.deptno, ',') within GROUP(ORDER BY t.deptno)), '([^,]+)(,\1)+', '\1') bl_number  3    FROM scott.emp t  4  ; DEPTNO                                                                           BL_NUMBER-------------------------------------------------------------------------------- --------------------------------------------------------------------------------10,10,10,20,20,20,20,20,30,30,30,30,30,30                                        10,20,30
The listparts is reordered successfully.



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.