首页 > 代码库 > oracle 中的null与''
oracle 中的null与''
1.先看看Null与‘‘在oracle中的表现
C:\Users\zen>sqlplus hr/hrSQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 31 10:30:32 2017Copyright (c) 1982, 2010, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> create table test_null(id_ number,name_ varchar2(10));Table created.SQL> insert into test_null values(1,‘oracle‘);1 row created.SQL> insert into test_null values(2,‘‘);1 row created.SQL> insert into test_null values(3,null);1 row created.SQL> select * from test_null; ID_ NAME_---------- ---------- 1 oracle 2 3SQL> select nvl(name_,‘It is null‘) nvl_null,nvl(‘‘,‘It is empty string‘) emptystr from test_null;NVL_NULL EMPTYSTR---------- ------------------oracle It is empty stringIt is null It is empty stringIt is null It is empty stringSQL> select * from test_null where name_ is null; ID_ NAME_---------- ---------- 2 3SQL> select * from test_null where name_=‘‘;no rows selectedSQL> select * from test_null where cast(name_ as varchar2(10))=‘‘;no rows selectedSQL> select * from test_null where cast(name_ as varchar2(10))=cast(‘‘ as varchar2(10));no rows selectedSQL> select * from test_null where name_<>‘‘;no rows selected
SQL> select * from test_null where nvl(name_,‘‘)=‘‘;
no rows selected
SQL> select * from test_null where nvl(name_,‘A‘)=‘A‘;
ID_ NAME_
---------- ----------
2
3
SQL>
2.关于以上现象的解释
oracle 将‘‘ 当成了null 处理。每个null都是独一无二的,对null的操作只能是 is null OR is not null,对于null的=<>,>,<的逻辑判断都会得到否。
3.看看null与‘‘在Mysql中的表现
C:\Users\zen>mysql -uzen -pEnter password: ****Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.24-log MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> use product_test;Database changedmysql> drop table test_null;Query OK, 0 rows affected (0.37 sec)mysql> create table test_null(id_ int,name_ varchar(127));Query OK, 0 rows affected (0.59 sec)mysql> insert into test_null values(1,‘oracle‘),(2,‘‘),(3,null);Query OK, 3 rows affected (0.08 sec)Records: 3 Duplicates: 0 Warnings: 0mysql> select * from test_null;+------+--------+| id_ | name_ |+------+--------+| 1 | oracle || 2 | || 3 | NULL |+------+--------+3 rows in set (0.00 sec)mysql> select * from test_null where name_ is null;+------+-------+| id_ | name_ |+------+-------+| 3 | NULL |+------+-------+1 row in set (0.06 sec)mysql> select * from test_null where name_=‘‘;+------+-------+| id_ | name_ |+------+-------+| 2 | |+------+-------+1 row in set (0.00 sec)mysql> select * from test_null where name_<>‘‘;+------+--------+| id_ | name_ |+------+--------+| 1 | oracle |+------+--------+1 row in set (0.00 sec)mysql> select * from test_null where name_ is not null;+------+--------+| id_ | name_ |+------+--------+| 1 | oracle || 2 | |+------+--------+2 rows in set (0.00 sec)mysql>
4.在mysql中null 就是null,‘‘就是空字符,没有将二者混淆起来。
oracle 中的null与''
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。