sql的where条件中是否null相关条件怎么写

如题所述

sql的where条件判断值是否为null,可以直接与NULL进行比较。

例:

select * from a where e=null;--检索表a中列e为NULL的数据
select * from a where e<>null;--检索表a中列e不为NULL的数据

检索环境和数据库管理系统的差异,部分环境不支持NULL值的直接比较,需要使用is null和is not nulll来判断空值NULL,上例脚本修改为:

select a,e from a where e is null;
select a,e from a where e is not null;

另外有些数据库,NULL值检索结果和空字符“”是一样的,为了区别,可以使用函数来更改NULL的显示。

例:MS SQL server中的isnull函数:

一、ISNULL语法格式
ISNULL ( check_expression , replacement_value )

二、参数简介
check_expression:将被检查是否为 NULL的表达式,check_expression可以是任何类型的。

replacement_value:在 check_expression 为 NULL时将返回的表达式,replacement_value 必须与 check_expresssion 具有相同的类型。

三、返回值
返回与 check_expression 相同的类型。如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。

实例:

 

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-04-04
比如从User 表 查找name是Null的
select *
from user
where name is null
-----------------------------------
name不是null
select * from use where name is not null本回答被提问者采纳
第2个回答  2016-04-04
is not null 不为空

is null 为空
相似回答