oracle的null,'null',''值在具体到写sql语句的时候,经常会产生疑虑,不知道是写成null还是'null'还是'',写的是否正确,因此实践了一下,解决自己在以后的顾虑。
1.字段与空值的比较:
select t.name from emps_table t where t.name <> 'null'
上述sql语句不能写为:
select t.name from emps_table t where t.name <> null
否则结果和自己想要的不一样
2.集合与空值的比较:
测试sql:
1. 假如select t.name from emps_table t where t.name <> '' 返回一个空集合
2. 测试集合与null的比较
select decode((select t.name from emps_table t where t.name <> ''),null,'1','2') from dual
结果输出:1 ,说明空集合==null
select decode((select t.name from emps_table t where t.name <> ''),‘null’,'1','2') from dual
结果输出:2,说明空集合!='null‘
3.其实,'null'==''
select t.name from emps_table t where t.name <> 'null'
select t.name from emps_table t where t.name <> ''
结果是一样的。