Oracle SQL Tree Operations

Source: Internet
Author: User

Syntax: Select...start with...connect By...prior

There are two main points

1) The prior is placed on the child node side, indicating that the scan tree is scanned from top to bottom as the node specified by start with the root node. May correspond to one or more branches.

Start with can be omitted if omitted, indicating that all nodes are traversed as root nodes, respectively

Select Deptid,deptname,dept_pid,dept_pname, leader,remark,deptdesc,sortsno,status,levelid from T_SYS_DEPT1
START with Deptid=#{treeroot} CONNECT by PRIOR deptid = Dept_pid;------------------------------------(root----> Leaf)

2) The prior is placed on the parent node, which means that the scan tree is scanned from bottom to top with the node specified in start with as the lowest layer child node. The order is that the child nodes are scanned toward the parent node until the root node, which can only get one branch.

Start with can be omitted, and if omitted, indicates that all nodes are traversed as the lowest level child nodes toward the root node respectively

Select Deptid,levelid from T_SYS_DEPT1
START with Deptid=#{id} CONNECT by PRIOR dept_pid = deptid;---------------------------------(leaf----> root)

Oracle SQL Tree Operations

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.