我们有一个代表组织结构图的视图。在图表的顶部,父节点为空,相应的字段为空,但也不为空(?)
这找不到任何东西:
select *
from the_weird_view t
where t.parent_nsq is null
但这有效:
select *
from the_weird_view t
where nvl(t.parent_nsq, -666) = -666
它似乎是由递归查询和非ansi连接的组合引起的。
这通常有效:
with
ANSI
as
(select c.code as child_code,
p.code as parent_code,
p.code_nsq as parent_nsq
from links l
join codes c on (c.code_nsq = l.child_code_nsq)
left join codes p on (p.code_nsq = l.parent_code_nsq)
connect by child_code_nsq = prior parent_code_nsq
start with parent_code_nsq is null)
--
select * from ANSI where parent_nsq is null
这表现得很奇怪:
WTF
as
(select c.code as child_code,
p.code as parent_code,
p.code_nsq as parent_nsq
from links l
, codes c
, codes p
where c.code_nsq = l.child_code_nsq
and p.code_nsq(+) = l.parent_code_nsq
connect by child_code_nsq = prior parent_code_nsq
start with parent_code_nsq is null)
--
-- select * from WTF where parent_code is null -- Works normally
-- select * from WTF where nvl(parent_nsq, 0) = 0 -- Works
select * from WTF where parent_nsq is null -- Returns nothing?!
我的问题,除了“什么?!”之外,这是一个错误,如果有什么事情可做呢(除了当然更新 the_weird_view )?
编辑:所以这听起来像一个普通的老bug。我们的版本是11g 64bit(11.2.0.4.0)。