select mt.id from category mt
where 1=1
start with mt.id = ${id}
connect by nocycle prior mt.id = mt.pid
mt.id = mt.pid 向下查找树节点
mt.pid = mt.id 向上查找树节点
根据树的层级排序:
使用 level 关键字 :输出树的层级
select t.id,t.parent_id,t.name,level from department t
where t.state = 1
start with t.parent_id = 1
connect by nocycle prior t.id = t.parent_id
order by level,t.sort