oracle查询数据树

时间:2022-01-13 12:58:20
connct By 的语法:
select ... from <TableName> 
where <Conditional-1>
start with <Conditional-2>
connect by <Conditional-3>;


<Conditional-1>:过滤条件,用于对返回的所有记录进行过滤。
<Conditional-2>:查询结果重起始根结点的限定条件。
<Conditional-3>:连接条件

/**
  * 通过Id查询下面的所有子项
  */
select * from t_system_bumen b
connect by prior b.id= b.parentnodesid 
start with b.id=要查询的ID


//或者
select * from t_system_bumen b
where b.id != 2377
start with b.id=2377
connect by prior b.id=b.parentnodesid




/**
  * 通过Id查询下面的所有父节点
  */
select * from t_system_bumen b
connect by prior b.parentnodesid= b.id 
start with b.id=2377


//或者


select * from t_system_bumen b
where b.id != 2377
start with b.id=2377
connect by prior b.parentnodesid=b.id