一直以为空字符串是就是NULL,当插入空字符串的时候就可以通过NULL,但是前段时间开发发现使用not in特定值后发现,空字符集居然也没有包括在内,当时我也认为,应该包括在内,后来做了个如下测试发现其实在DB2中NULL和空串真不是一回事。
create table tab
( id integer not null,
name char(50),
empid char(10),
salary char(15)
);
insert into tab values(1,'JACK','0001','2000');
insert into tab values(2,'TOM','0002','');
insert into tab values(3,'LUCY','0003','3000');
insert into tab values(4,'JAME','0004','');
insert into tab values(4,'KIM','0005',null);
db2 => select * from tab;
select * from tab
ID NAME EMPID SALARY
----------- -------------------------------------------------- ---------- ---------------
1 JACK 0001 2000
2 TOM 0002
3 LUCY 0003 3000
4 JAME 0004
4 KIM 0005 -
5 record(s) selected.
db2 => select * from tab where salary not in ('2000','3000');
select * from tab where salary not in ('2000','3000')
ID NAME EMPID SALARY
----------- -------------------------------------------------- ---------- ---------------
2 TOM 0002
4 JAME 0004
2 record(s) selected.
db2 => select * from tab where salary is null;
select * from tab where salary is null
ID NAME EMPID SALARY
----------- -------------------------------------------------- ---------- ---------------
4 KIM 0005 -
推荐阅读: