https://www.cnblogs.com/wanggang-java/p/10916426.html#_labelTop
connect by主要用于父子,祖孙,上下级等层级关系的查询
回到顶部
语法
{ CONNECT BY [ NOCYCLE ] condition [AND condition]… [ START WITH condition ]
| START WITH condition CONNECT BY [ NOCYCLE ] condition [AND condition]…}
– 创建表
create table employee(
emp_id number(18),
lead_id number(18),
emp_name varchar2(200),
salary number(10,2),
dept_no varchar2(8)
);
– 添加数据
insert into employee values(‘1’,0,‘king’,‘1000000.00’,‘001’);
insert into employee values(‘2’,1,‘jack’,‘50500.00’,‘002’);
insert into employee values(‘3’,1,‘arise’,‘60000.00’,‘003’);
insert into employee values(‘4’,2,‘scott’,‘30000.00’,‘002’);
insert into employee values(‘5’,2,‘tiger’,‘25000.00’,‘002’);
insert into employee values(‘6’,3,‘wudde’,‘23000.00’,‘003’);
insert into employee values(‘7’,3,‘joker’,‘21000.00’,‘003’);commit;
查询以emp_id为6开始的节点
select emp_id,lead_id,emp_name,salary
from employee
start with emp_id=6
connect by prior lead_id=emp_id;
**prior 后面是什么就以这个条件找上级节点**
来源:CSDN
作者:ademen
链接:https://blog.csdn.net/ademen/article/details/104310629