下面是我测试的一个小例子。
在数据库中有 test_dept 表
select t.* from test_dept t;
查询的结果如下,很简单的表就不上传建表语句了。
树形查询语句
select e.* from test_dept e start with e.id=1 connect by e.parent_id=prior e.id;
start with :指定查询的根行。connect by :指定子行和父行的关系。
prior : 引用父行的id。