码迷,mamicode.com
首页 > 数据库 > 详细

oracle 中的null与''

时间:2017-03-31 11:47:47      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:option   1.2   with   sel   comm   monitor   res   pass   rpo   

1.先看看Null与‘‘在oracle中的表现

C:\Users\zen>sqlplus hr/hr

SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 31 10:30:32 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 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
         3

SQL> select nvl(name_,It is null) nvl_null,nvl(‘‘,It is empty string) emptystr from test_null;

NVL_NULL   EMPTYSTR
---------- ------------------
oracle     It is empty string
It is null It is empty string
It is null It is empty string

SQL> select * from test_null where name_ is null;

       ID_ NAME_
---------- ----------
         2
         3

SQL> select * from test_null where name_=‘‘;

no rows selected

SQL> select * from test_null where cast(name_ as varchar2(10))=‘‘;

no rows selected

SQL> select * from test_null where cast(name_ as varchar2(10))=cast(‘‘ as varchar2(10));

no rows selected

SQL> 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 -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \h for help. Type \c to clear the current input statement.

mysql> use product_test;
Database changed
mysql> 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: 0

mysql> 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与''

标签:option   1.2   with   sel   comm   monitor   res   pass   rpo   

原文地址:http://www.cnblogs.com/Alex-Zeng/p/6650529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!