您的位置:首页 > 数据库 > Oracle

浅谈oracle 空值null与'null',''

2013-10-23 15:42 337 查看
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 <> ''

    结果是一样的。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: