我有一个查询要查看数据的父子层次列表。在运行以下查询时,我得到了错误 ORA-01436
。
SELECT ParentPropertyRSN, CONNECT_BY_ROOT PropertyRSN as PropertyRSN,
LEVEL, SYS_CONNECT_BY_PATH(ParentPropertyRSN, '/') Path
FROM Property
CONNECT BY PRIOR PropertyRSN = ParentPropertyRSN
order by level desc;
所以我在 CONNECT BY
子句中添加了 NOCYCLE
并获得了完整的数据列表及其层次路径
现在我需要一个查询来获取包含导致 ORA-01436
的不准确数据的行的列表。
最佳答案
您确实应该使用 NOCYCLE
来避免无限循环。最重要的是,您可以使用 CONNECT_BY_ISCYCLE
来识别违规行:
SELECT
ParentPropertyRSN,
CONNECT_BY_ROOT PropertyRSN as PropertyRSN,
LEVEL,
SYS_CONNECT_BY_PATH(ParentPropertyRSN, '/') Path,
CONNECT_BY_ISCYCLE Has_Cycle
FROM Property
CONNECT BY NOCYCLE PRIOR PropertyRSN = ParentPropertyRSN
ORDER BY level desc;
来自 the documentation :
The
CONNECT_BY_ISCYCLE
pseudocolumn returns1
if the current row has a child which is also its ancestor. Otherwise it returns0
.You can specify
CONNECT_BY_ISCYCLE
only if you have specified theNOCYCLE
parameter of theCONNECT BY
clause.NOCYCLE
enables Oracle to return the results of a query that would otherwise fail because of aCONNECT BY
loop in the data.
关于sql - 如何找到导致ORA-01436的不正确数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60435293/