[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;