1、创建测试表,create table test_connect(id number, p_id number);
2、插入测试数据,
insert into test_connect values(1,1);
insert into test_connect values(2,1);
insert into test_connect values(3,2);
insert into test_connect values(4,3);
commit;
3、查询数据表内容,select * from test_connect ,
4、执行递归查询语句,加入nocycle要素,不会出现【ORA-01436: 用户数据中的 CONNECT BY 循环的错误】,执行结果如下,
select *
from test_connect t
start with id = 4
connect by nocycle prior t.p_id = t.id
可以指定根节点,到根节点处停止递归
select sd.id,
sd.parent_id,
sd.name,
connect_by_root(sd.id) city_id, -- 递归查询到根节点的ID
connect_by_root(sd.name)city_name -- 递归查询到根节点的name
from sc_district sd
where sd.name = '响滩镇' -- 定位到树的叶子节点
start with parent_id = 1 -- 从下到上遍历到根节点,只到parent_id =1 才结束遍历(可以想象成遍历到树根,第一级别节点)
connect by prior id= sd.parent_id -- 自下而上,下一行的id等于这一行的parent_id
select id from ( select id ,PARENTLOGID from 表一 connect by nocycle prior PARENTLOGID=id START WITH id='3' ) where PARENTLOGID is null
treeview.selectednode.parentnode貌似有这个属性,你找找parent
楼主您好
可以试试connect by prior替换成connect by nocycle prior