oracle 递归 通过子节点查根节点
SELECTsectype.thekey,sectype.name,sectype.thelevelFROMsectypestartwithsectype.thekey=...
SELECT sectype.thekey, sectype.name, sectype.thelevel
FROM sectype
start with sectype.thekey = '8565'
connect by prior sectype.thelevel = sectype.thekey
其中8565是子节点的id。我现在想通过这个子节点查到对应的根节点的id,该如何查询? 展开
FROM sectype
start with sectype.thekey = '8565'
connect by prior sectype.thelevel = sectype.thekey
其中8565是子节点的id。我现在想通过这个子节点查到对应的根节点的id,该如何查询? 展开
2个回答
展开全部
根节点的thelevel 应该为null,可以加个条件 where sectype.thelevel is null 。
SELECT sectype.thekey, sectype.name, sectype.thelevel
FROM sectype
where sectype.thelevel is null
start with sectype.thekey = '8565'
connect by prior sectype.thelevel = sectype.thekey
SELECT sectype.thekey, sectype.name, sectype.thelevel
FROM sectype
where sectype.thelevel is null
start with sectype.thekey = '8565'
connect by prior sectype.thelevel = sectype.thekey
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询