Oracle tree structure query statement

Source: Internet
Author: User


Select rpad ('', 4 * (LEVEL-1), '--') | name as name, CONNECT_BY_ROOT name" ROOT ", www.2cto.com CONNECT_BY_ISLEAF" ISLEAF ", LEVEL, t. *, SYS_CONNECT_BY_PATH (t. name, '/') "PATH" from sys_department t start with t. required mentid = 1 connect by nocycle prior t. required mentid = T. parent1_mentid order siblings by t. departmentid; select rpad ('', 2 * (LEVEL-1), '-') | Tn_Id, CONNECT_BY_ROOT Tn_Id" ROOT ", CONNECT_BY_ISLEAF" ISLEAF ", LEVEL, t. *, SYS_CONNECT_BY_PATH (t. tn_Id, '/') "PATH" from (SELECT c. tn_id, c. tn_name, c. parent_id, c. orders FROM tree_node_c c where c. proj_phase = 'pd 'and (c. view_mode = 2 or c. view_mode = 0) union select d. tn_id, d. tn_name, d. parent_id, d. orders from tree_node_d d where d. proj_id = '15-B154C 'AND (d. view_mode = 2 or d. view_mode = 0) and d. proj_phase = 'pd ') t start with t. parent_Id = 'dp1 _ 000' connect by nocycle prior t. tn_Id = T. PARENT_ID order siblings by orders

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.