sql判断某个字段是否为空

218 阅读1分钟

空字段的表述包含两种:一种是空值,一种是空串

1、sql判断空值的方法

//查询空值记录
select * from 表名 where 字段名 is null
//查询不是空值的记录
select * from 表明 where 字段名 is not null

2、sql判断空串的方法

//查询空串的记录
select * from 表名 where 字段名 = ''
//查询不是空串的记录
select * from 表名 where 字段名 <> ''

3、sql判断空值和空串的方法

//查询不为空、不是空串的记录
select * from 表名 where length(字段名) > 0
//查询空、空串的记录
select * from 表名 where length(字段名) <= 0