关键词start with…connect by
create table diqu
(id int ,
address varchar2(10) not null,
parent_id int
);
insert into diqu(id,address,parent_id) values(100,'中国','0');
insert into diqu(id,address,parent_id) values(110,'湖南','100');
insert into diqu(id,address,parent_id) values(130,'四川','100');
insert into diqu(id,address,parent_id) values(120,'湖北','100');
insert into diqu(id,address,parent_id) values(111,'长沙','110');
insert into diqu(id,address,parent_id) values(112,'株洲','110');
insert into diqu(id,address,parent_id) values(113,'衡阳','110');
insert into diqu(id,address,parent_id) values(121,'武汉','120');
insert into diqu(id,address,parent_id) values(122,'黄冈','120');
insert into diqu(id,address,parent_id) values(131,'成都','130');
insert into diqu(id,address,parent_id) values(132,'乐山','130');
select * from diqu
--prior在前 查爸爸
select *from diqu start with id=130
connect by diqu.id=prior parent_id;
--prior在后 查儿子
select *from diqu start with id=130
connect by prior diqu.id= parent_id;