详细参考:http://blog.csdn.net/crazyxingjc/article/details/7756299
语法:
select * from table start with cond1 connect by cond2 where cond3;
典型的查询方式:
(1)查子节点
select t.id, t.pid, t.name from t_tree t start with t.id = 100 --开始节点 connect by prior t.id = t.pid; -- id优先,向下查子节点 -- 或 connect by t.pid = prior t.id
(2)查父节点
select t.id, t.pid, t.name from t_tree t start with t.id = 100 --开始节点 connect by prior t.pid = t.id; -- pid优先,向上查父节点 -- 或 connect by t.id = prior t.pid
(3)只查本节点,不加prior即可