[Oracle] Tree Structure Query

Source: Internet
Author: User

[Oracle] Tree Structure Query [SQL] -- tree structure query in oracle is actually a sequential traversal-displays the tree with KING as the root node, start with defines the START Node SELECT * FROM emp a start WITH. empno = 7839 connect by prior. empno =. mgr; -- placed before the equal sign, retrieved FROM the parent node to the child node; placed behind the equal sign, then retrieved FROM the child node to the parent node www.2cto.com SELECT * FROM emp a start with. empno = 7839 connect by prior. empno =. mgr; -- use the pseudo column level to display the hierarchical relationship SELECT * FROM emp a start with. empno = 7839 connect by prior. empno =. mgr; SELECT level,. * FROM emp a start with. empno = 7839 connect by prior. empno =. mgr; -- use the function sys_connect_by_path to display the full path select level, sys_connect_by_path (. ename, '/'),. * FROM emp a start with. empno = 7839 connect by prior. empno =. mgr; -- The where clause only limits a single node and does not affect the select level, sys_connect_by_path (. ename, '/'),. * FROM emp a WHERE. empno <> 7369 start with. empno = 7839 connect by prior. empno =. mgr; -- connect by Clause limits the entire branch www.2cto.com -- connect_by_root with the current node as the starting node to display the select level, connect_by_root (. job), sys_connect_by_path (. ename, '/'),. * FROM emp a WHERE. empno <> 7369 start with. empno = 7839 connect by prior. empno =. mgr; -- connect_by_isleaf shows whether the current row has leaf nodes, 1: yes; 0: No select level, connect_by_isleaf, sys_connect_by_path (. ename, '/'),. * FROM emp a WHERE. empno <> 7369 start with. empno = 7839 connect by prior. empno =. new features starting from mgr; -- connect_by_iscycle 10g are used to determine whether the current node has a loop, 0: No; 1: select level, connect_by_iscycle, connect_by_isleaf, sys_connect_by_path (. ename, '/'),. * FROM emp a WHERE. empno <> 7369 start with. empno = 7839 connect by nocycle prior. empno =. mgr;

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.