oracle获取树状结构数据

语法:

select * from 表名 where 条件1
start with 条件2
connect by 条件3;

条件2: 是根结点的限定语句,当然可以放宽限定条件,以取得多个根结点,实际就是多棵树。
条件3: 是连接条件,其中用PRIOR表示上一条记录,比如 CONNECT BY PRIOR org_id = parent_id;就是说上一条记录的org_id 是本条记录的parent_id,即本记录的父亲是上一条记录。

例:

select * from T_SYS_ORG_RELATION t where t.is_delete = '0'
start with t.org_id = '根节点org_id'
connect by prior t.org_id = t.parent_id
posted @ 2023-02-17 16:51  晚风没有颜色  阅读(111)  评论(0编辑  收藏  举报