本节内容:
Oracle递归查询
测试环境:
部门表: ID,PID
oracle递归查询的例子:
复制代码 代码示例:
--查询所有
select count(1) from TD t
--向下找包含自己
select count(1) from TD connect by prior ID=PID start with ID='?'
--向下找不包含自己
select count(1) from TD start with PID='?' connect by prior ID=PID
--向上找包含自己
select count(1) from TD start with ID='?' connect by prior PID=ID
--向下找包含自己
select count(1) from TD start with ID='?' connect by prior ID=PID
--向下找不包含自己
select count(1) from TD start with PID='?' connect by prior ID=PID
--查询部门下的一级子部门,并且每行后都包含自己
select * from TD start with PID='?' connect by prior PID=ID
--查询当前部门了所有一级子部门
select count(1) from TD t where t.PID='?'