Sys_connect_by_path Functions in Oracle

Source: Internet
Author: User

Create TableTest (Avarchar2(Ten), bvarchar2(Ten)); INSERT  intoTEST (A, B)VALUES('1','I'm'); INSERT  intoTEST (A, B)VALUES('1','our'); INSERT  intoTEST (A, B)VALUES('2','a'); INSERT  intoTEST (A, B)VALUES('2','from'); COMMIT; SELECTA, B fromTEST A B---------- ----------  1I'm1our2a2It is now necessary to achieve the following effect, A B---------- ----------  1me, guys.2One, up

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

SELECTALTRIM(MAX(Sys_connect_by_path (B,',')),',') B from(SELECTB, A, Row_number () Over(PARTITION byAORDER  byBDESC) RN fromTEST) START withRn= 1CONNECT byRn- 1 =PRIOR RN andA=PRIOR AGROUP  byA

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.

Excerpt from: http://database.51cto.com/art/201010/231125.htm

Sys_connect_by_path functions 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.