The magical function of Sys_connect_by_path in Oracle

Source: Internet
Author: User

In Oracle, the primary function of the Sys_connect_by_path function is to differentiate all child nodes under a parent node by a character, and then connect to display in a single column.

AD:



The Sys_connect_by_path function in Oracle is a very important function, and here is an example of using the Sys_connect_by_path function, as follows:

      
  
 
  1. CREATE TABLE Test (a varchar2 (ten), B varchar2 (10));
  2. INSERT into TEST (A, B) VALUES (' 1 ', ' I ');
  3. INSERT into TEST (A, B) VALUES (' 1 ', ' they ');
  4. INSERT into TEST (A, B) VALUES (' 2 ', ' one ');
  5. INSERT into TEST (A, B) VALUES (' 2 ', ' up ');
  6. COMMIT;
  7. SELECT A, B from TEST
  8. A B
  9. ---------- ----------
  10. 1 I
  11. 1 of them
  12. 21
  13. From 2
  14. Now it is necessary to achieve the following effect,
  15. A B
  16. ---------- ----------
  17. 1 me, guys.
  18. 21, up

Just want to use one sentence of SQL to return the result.

      
 
   
  
  1. START with RN = 1
  2. CONNECT by RN- 1 = PRIOR
  3. and A = PRIOR

The main function of the Sys_connect_by_path function is that all child nodes under a parent node can be distinguished by a character, and then the connection is displayed in a column.

The purpose of the Row_number function is very extensive, and the function is to generate a sequence number for each row of records that are queried. The method of producing the serial number is controlled by the statement inside the over () function.

The magical function of Sys_connect_by_path in Oracle

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.