前言
最近发现带的小伙伴写sql对于空值的判断方法不正确,导致程序里面的数据产生错误,在此进行一下整理,方便大家以后正确的判断空值。以下带来示例给大家进行讲解。
建表
create table test (colA varchar(10) not null,colB varchar(10) null);
向test表中插入数据
插入colA为null的数据
insert into test values (null,1);
此时会报错,因为colA列不能为null。
插入colB为null的数据
insert into test values (1,null);
发现插入成功。
插入都为空的数据
insert into test values ('','');
插入colA为空的数据
insert into test values ('',null);