这个选项怎么样?如果你的值从不为空,我认为它可能有效。
where not (value = column)
这将导致以下真值表用于评估 where 子句。
col1
| 'bla' | null |
| 'bla' | F | T |
value
| null | T | *T |
*这是唯一一个“错误”的,但没关系,因为我们的值永远不会为空
更新
好的,我刚刚尝试了我的想法,但失败了。我将在此处保留答案,以节省其他人尝试相同事情的时间。以下是我的结果:
select 'x', 'x' from dual where not ('x' = 'x');
0 rows
select 'x', 'y' from dual where not ('x' = 'y');
1 row
select 'x', 'null' from dual where not ('x' = null);
0 rows
select 'null', 'null' from dual where not (null = null);
0 rows
更新 2
如果您的值从不为空(与上面的真值表匹配),则此解决方案有效。
where ('blah' != col1 or col1 is null)
这里是测试:
select 'x', 'x' from dual where ('x' != 'x' or 'x' is null);
0 rows
select 'x', 'y' from dual where ('x' != 'y' or 'y' is null);
1 row
select 'x', 'null' from dual where ('x' != null or null is null);
1 row
select 'null', 'null' from dual where (null != null or null is null);
1 row
WHERE NULLIF(col1, 'blah') IS NOT NULL ...
。这很可能会产生与 NVL 方法相同的性能影响。更好的方法是使用IS DISTINCT FROM
,但正如 @BillKarwin 所指出的那样,Oracle 不支持该方法。 - pilcrowNVL(col1,'X')!='blah'
或(col1!='blah' OR col1 IS NULL)
进行查询将没有显着的性能差异。 - Jeffrey Kemp