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与''的更多相关文章

  1. Oracle中的NULL、’’(空字符串)以及’_’(空格)

    本文首发于 http://youngzy.com/ 在Oracle中使用 null,''(空字符串),'_'(空格)时,有没有遇到问题?产生疑惑? null和’’(空字符串)是一个意思 注: 为了便于 ...

  2. 【转】oracle中的NULL、''(空字符串)以及'_'(空格)

    在Oracle中使用null,''(空字符串),'_'(空格)时,有没有遇到问题?产生疑惑? 1.NULL和''(空字符串)是一个意思 注:为了便于区分空字符串和空格,下面的示例均以'_'代表空格. ...

  3. Oracle中的null

    测试数据:公司部分员工基本信息

  4. Oracle中的null与空字符串''的区别

    含义解释:问:什么是NULL?答:在我们不知道具体有什么数据的时候,也即未知,可以用NULL,我们称它为空,ORACLE中,含有空值的表列长度为零.ORACLE允许任何一种数据类型的字段为空,除了以下 ...

  5. oracle中空值null的判断和转换:NVL的用法

    1.NULL空值概念 数据库里有一个很重要的概念:空值即NULL.有时表中,更确切的说是某些字段值,可能会出现空值, 这是因为这个数据不知道是什么值或根本就不存在. 2.NULL空值判断 空值不等同于 ...

  6. oracle 中关于null的操作

    空值 空值一般用NULL表示 一般表示未知的.不确定的值,也不是空格 一般运算符与其进行运算时,都会为空 空不与任何值相等 表示某个列为空用:IS NULL  不能使用COMM=NULL这种形式 某个 ...

  7. oracle中如何处理null

    从两个表达式返回一个非 null 值.语法NVL(eExpression1, eExpression2)参数eExpression1, eExpression2如果 eExpression1 的计算结 ...

  8. Oracle 在not in中使用null的问题

    http://www.linuxidc.com/Linux/2012-07/66212.htm 以前还专门小总结过一下Oracle中关于NULL的一些问题,碰巧今天在看书的过程中又看到了另外一个以前没 ...

  9. oracle中的函数

    ORACLE中函数          Oracle已经内建了许多函数,不同的函数有不同的作用和用法,有的函数只能作用在一个记录行上,有的能够作用在多个记录行上,不同的函数可能处理不同的数据类型.常见的 ...

随机推荐

  1. js中this

    首先声明,我是小白,以下只是自己的简单理解. 先看下面的代码: (function () { console.log(this); })(); 毫无疑虑,输出的是window. 在看下面代码: (fu ...

  2. Zend Server 安装与配置图文教程

    Zend Server是一款专业的PHP Web开发应用服务器,一些初次接触并使用此程序的朋友可能不太了解安装方法,本文为您提供了Zend Server 安装与配置图文教程,欢迎大家阅读,并提出自己的 ...

  3. C语言学习笔记--接续符和转义符

    1.C语言中的接续符 (1)编译器将反斜杠剔除,跟在反斜杠后面的字符自动接续到前一行 (2)在接续单词时,反斜杠之后不能有空格,反斜杠下一行之前也不能有空格 (3)接续符适合在宏定义代码块时使用 #i ...

  4. 【转】GitHub使用

    1.设置Git全局用户配置 git config --global user.name "xxx" git config --global user.email xxx@gmail ...

  5. cadence spb 16.5 破解过程实例和使用感受_赤松子耶_新浪博客

    cadence spb 16.5 破解过程实例和使用感受_赤松子耶_新浪博客 Cadence Allegro16.5详细安装具体的步骤 1.下载SPB16.5下来后,点setup.exe,先安装第一项 ...

  6. 【jeasyui5】样式:调整页面显示的顶部菜单和左侧菜单

    1.顶部菜单修改:修改index2.js里面的InitTopMenu方法,将icon +2 2.左侧菜单宽度调整: 修改index.html,加上width:170的定长 <!-- 左侧菜单 - ...

  7. invalid loc header的解决办法

    eclipse 运行程序,报invalid loc header,网上一查,删除maven仓库(默认位于%USERPROFILE%\.m2\repository\org)中的下载包,然后重新下载.

  8. C语言函数调用的底层机制

    由这个文章引入吧(百度文库:http://wenku.baidu.com/link?url=aAm1tBg4okqIyFAmfgrJBHdPDrri5LUEKrJjn-dNITds5lwSm550DT ...

  9. 获取指定日期相关DATENAME和DATEPART数据

    DATENAME和DATEPART有何区别,Insus.NET写成一个函数,可以方便查询与对比: 一个是返回一个字符串,另一个是返回一个整数. SET ANSI_NULLS ON GO SET QUO ...

  10. 在Android中使用Protocol Buffers(下篇)

    本文来自网易云社区. FlatBuffers编码数组 编码数组的过程如下: 先执行 startVector(),这个方法会记录数组的长度,处理元素的对齐,准备足够的空间,并设置nested,用于指示记 ...