【问题标题】:Nulls removed by backslash filter [closed]反斜杠过滤器删除的空值[关闭]
【发布时间】:2021-01-15 22:30:56
【问题描述】:

我遇到了空值被反斜杠删除的情况。我没有在网上找到示例,所以我想我会分享它。

create table test(col varchar(10))
insert into test values ('a'),(null),('b')
select * from test where col != '\'
col
a
b

【问题讨论】:

标签: sql filter null


【解决方案1】:

这是正确的。几乎所有与NULL 的比较都会导致NULL 被视为错误。标准 SQL 有一个NULL-safe 比较运算符:

select *
from test
where col is distinct from '\';

大多数数据库不支持这一点,因此通常需要进行显式比较:

select *
from test
where col <> '\' or col is null;

【讨论】:

    【解决方案2】:

    简单的答案是NULL 不能通过除IS NULL 之外的任何表达式。

    您需要使用IS NULL,如下:

    select * from test where col != '\' or col is null
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 2018-07-26
      • 2019-11-19
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      相关资源
      最近更新 更多