我们想写这个查询:
select * from table
where col1 != 'blah' and col2 = 'something'
Run Code Online (Sandbox Code Playgroud)
我们希望查询包含col1为null的行(而col2 ='something').目前,查询不会对col1为null的行执行此操作.以下查询是最好还是最快的方法吗?
select * from table
where (col1 != 'blah' or col1 is null) and col2 = 'something'
Run Code Online (Sandbox Code Playgroud)
或者,如果需要,我们可以将所有col1 null值更新为空字符串.这会是一个更好的方法吗?然后我们的第一个查询将工作.
更新:Re:使用NVL:我在另一篇文章中读到,从性能角度来看,这不是一个很好的选择.
我有一个变量传递给我的存储过程,它是一个过滤器(基本上).但是,该字段有时可以为null,如果是,我希望能够检查具有该字段的行为null.
例如,
表A:
VALUE_COLUMN | FILTER_COLUMN
----------------------------
A | (NULL)
B | (NULL)
C | (NULL)
D | (NULL)
A | 1
E | (NULL)
F | (NULL)
B | 1
Run Code Online (Sandbox Code Playgroud)
查询(带输入,val,过滤器):
SELECT COUNT(1)
FROM TableA
WHERE
wrap_up_cd = val
AND brn_brand_id = filter
Run Code Online (Sandbox Code Playgroud)
预期的I/O:
val = A, filter = (null) = 1
val = A, filter = 1 = 1
val = C, filter = 1 = 0
Run Code Online (Sandbox Code Playgroud)
如何让Oracle以这种方式运行?