开发者

How to make CONNECT BY parameter optional

开发者 https://www.devze.com 2023-04-06 07:06 出处:网络
I have a procedure that uses Connect By SELECT开发者_开发百科 <lots of fields> FROM Group g

I have a procedure that uses 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
;

The number 1337 is a parameter on this procedure, if this value is 0 I would like to ignore the connect by code and execute everything else.

How can I handle this?


The most obvious answer is to test for the exception value in the connect by clause:

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消