我有一个程序使用Connect By
SELECT <lots of fields>
FROM Group g
<joins>
WHERE <where>
CONNECT BY PRIOR g.ID = g.ParentID
START WITH g.ID = 1337
ORDER SIBLINGS BY g.Name
;
数字1337
是这个过程的一个参数,如果这个值是0
,我想忽略connect by
代码并执行其他所有内容。
我该如何处理?
最明显的答案是测试connect by
子句中的异常值:
SELECT <lots of fields>
FROM Group g
<joins>
WHERE <where>
CONNECT BY PRIOR g.ID = g.ParentID and :param <> 0
START WITH g.ID = :param or :param = 0
ORDER SIBLINGS BY g.Name;