1.以oracle为例

SQL> create table test(id int primary key,content varchar(20));

SQL> INSERT INTO test (id, content) VALUES (1, NULL);

SQL> INSERT INTO test (id, content) VALUES (2, '');

SQL> INSERT INTO test (id, content) VALUES (3, ' ');

SQL> INSERT INTO test (id, content) VALUES (4, 'x');

SQL> select * from test;

ID CONTENT

---------- --------------------

1

2

3

4 x

SQL> SELECT ID,CONTENT,

case when content is null then 1 else 0 end as isnull,

case when content = '' then 1 else 0 end as isempty,

case when content = ' ' then 1 else 0 end as blank

from

test;

ID CONTENT ISNULL ISEMPTY BLANK

---------- -------------- ---------- ---------- ----------

1 1 0 0

2 1 0 0

3 0 0 1

4 x 0 0 0

SQL> select id,content,length(content) from test;

ID CONTENT LENGTH(CONTENT)

---------- -------------------- ---------------

1

2

3 1

4 x 1

SQL>

从结果可以看到,empry string被插入表中时,被当做NULL对待。因此,empty strings不会在数据库中存储。 单个空格是不会被转换的,因为不是一个empty string。

2.以mysql为例

>create table test(id int primary key,content varchar(20));

>INSERT INTO test (id, content) VALUES (1, NULL);

>INSERT INTO test (id, content) VALUES (2, '');

>INSERT INTO test (id, content) VALUES (3, ' ');

>INSERT INTO test (id, content) VALUES (4, 'x');

>select * from test;

+----+---------+

| id | content |

+----+---------+

| 1 | NULL |

| 2 | |

| 3 | |

| 4 | x |

+----+---------+

4 rows in set (0.00 sec)

>SELECT ID,CONTENT,

case when content is null then 1 else 0 end as isnull,

case when content = '' then 1 else 0 end as isempty,

case when content = ' ' then 1 else 0 end as blank

from

test;

+----+---------+--------+---------+-------+

| ID | CONTENT | isnull | isempty | blank |

+----+---------+--------+---------+-------+

| 1 | NULL | 1 | 0 | 0 |

| 2 | | 0 | 1 | 1 |

| 3 | | 0 | 1 | 1 |

| 4 | x | 0 | 0 | 0 |

+----+---------+--------+---------+-------+

4 rows in set (0.00 sec)

>select id,content,length(content) from test;

+----+---------+-----------------+

| id | content | length(content) |

+----+---------+-----------------+

| 1 | NULL | NULL |

| 2 | | 0 |

| 3 | | 1 |

| 4 | x | 1 |

+----+---------+-----------------+

可以看到NULL和empty string是不同的。而empty string和空格string被认为是相同的,但是在计算长度的时候却又不同了。

3.以pg为例

postgres=# create table test(id int primary key,content varchar(20));

postgres=# INSERT INTO test (id, content) VALUES (1, NULL);

postgres=# INSERT INTO test (id, content) VALUES (2, '');

postgres=# INSERT INTO test (id, content) VALUES (3, ' ');

postgres=# INSERT INTO test (id, content) VALUES (4, 'x');

postgres=# select * from test;

id | content

----+---------

1 |

2 |

3 |

4 | x

(4 rows)

postgres=# SELECT ID,CONTENT,

case when content is null then 1 else 0 end as isnull,

case when content = '' then 1 else 0 end as isempty,

case when content = ' ' then 1 else 0 end as blank

from test;

id | content | isnull | isempty | blank

----+---------+--------+---------+-------

1 | | 1 | 0 | 0

2 | | 0 | 1 | 0

3 | | 0 | 0 | 1

4 | x | 0 | 0 | 0

(4 rows)

postgres=# select id,content,length(content) from test;

id | content | length

----+---------+--------

1 | |

2 | | 0

3 | | 1

4 | x | 1

(4 rows)

postgres=#

看前两行,NULL被插入后仍被当做NULL,不能当做empty string。从第二行可以看到,插入的empty string没有被当做NULL,仍然是一个empty string。

NULLs和non-NULLs

(1)oracle数据库

SQL> SELECT id, content,

content || NULL AS concatnull,

content || 'x' AS concatchar

FROM test;

ID CONTENT CONCATNULL CONCATCHAR

---------- -------------------- -------------------- ---------------------

1 x

2 x

3 x

4 x x xx

SQL>

在oracle中,NULLs和字符相连接后,输出结果是字符。

(2)mysql数据库

>SELECT id, content,

content || NULL AS concatnull,

content || 'x' AS concatchar

FROM test;

+----+---------+------------+------------+

| id | content | concatnull | concatchar |

+----+---------+------------+------------+

| 1 | NULL | NULL | NULL |

| 2 | | NULL | 0 |

| 3 | | NULL | 0 |

| 4 | x | NULL | 0 |

+----+---------+------------+------------+

mysql中可以用concat拼接多个,但用||无法拼接字符串,会显示零。

>SELECT id, content,

concat(content,NULL) AS concatnull,

concat(content,'x') AS concatchar

FROM test;

+----+---------+------------+------------+

| id | content | concatnull | concatchar |

+----+---------+------------+------------+

| 1 | NULL | NULL | NULL |

| 2 | | NULL | x |

| 3 | | NULL | x |

| 4 | x | NULL | xx |

+----+---------+------------+------------+

NULL和non-NULLS拼接结果是NULL

(3)pg数据库

postgres=# SELECT id, content,

postgres-# content || NULL AS concatnull,

postgres-# content || 'x' AS concatchar

postgres-# FROM test;

id | content | concatnull | concatchar

----+---------+------------+------------

1 | | |

2 | | | x

3 | | | x

4 | x | | xx

(4 rows)

postgres=#

在pg中,NULLs和字符相连接后,NULL出现在任何一个值中都意味着结果是NULL作为输出值,而不管它连接的是什么。

oracle类似isempty,NULLs和empty strings在不同数据库的中特点相关推荐

  1. oracle blob 限制大小_Oracle的INSTANCE CAGING在数据库资源池中的作用

    现在的服务器都十分强大,哪怕一台两路服务器也可以拥有3-40个核,7-80个线程,远比十多年前的一台小机强大.在一台X86服务器上运行Oracle数据库,最大的问题是CPU资源很难得到充分的利用.我们 ...

  2. Oracle数据库查询表中记录为空,Empty result set fetched

    Oracle数据库查询表中记录为空,Empty result set fetched,此时没有数据,获取不到任何值,但是此时我们需要根据结果来做计算,因此可以使用count()函数来做结果统计,将统计 ...

  3. Oracle基础知识之synonym(同义词)、database link(数据库链接)、数据完整性

    Oracle基础知识之同义词.数据库链接.数据完整性 一.同义词 (一)概念 (二)分类 1.私有同义词 2.公共同义词 3.远程同义词 (三)作用 二.数据库链接 (一)概念 (二)分类 1.私有数 ...

  4. oracle创建表t sql语句,t-sql语句创建数据库

    DB2数据库常用工具 1解释工具 1.1 Visual Explain 之前都是explain就可以了昂Visual Explain是一种GUI工具,他为数据库管理员和应用程序开发人员提供了查看为特定 ...

  5. oracle数据库有哪些文件构成,Oracle数据库架构中包括几层?每层都有什么元素?...

    Oracle数据库架构中包括几层?每层都有 什么元素? 1 PL/SQL代表 A PROCEDURAL LANGUAGE/SQL B PROGRAM LANGUAGE SQL C POWER LANG ...

  6. oracle停止一切进程,oracle启动/停止的几种方法以及 启动和停止过程中出错的解决办法...

    一.启动几种方法: 1. sqlplus /nolog connect /as sysdba startup 2. sqlplus /nolog connect /as sysdba startup ...

  7. oracle修改表结构的sql命令是什么,sql语句中修改表结构的命令是什么?

    sql语句中修改表结构的命令是:"ALTER TABLE"命令. ALTER TABLE 语句用于在已有的表中添加.删除或修改列. SQL ALTER TABLE 语法 如需在表中 ...

  8. oracle11g ora 29927,【案例】Oracle内存泄漏 进行10046跟踪分析07445导致数据库宕机

    天萃荷净 在一次ORA-7445导致oracle数据库down掉故障分析中,发现sql因某种原因导致大量的sql area中很多内存泄露,最终导致数据库down掉.通过实验找出类此奇怪SQL. SEL ...

  9. 将oracle冷备份恢复到另外一个数据库实例中

    因更换服务器需要将Oracle数据库转移到另外台Oracle中. 说明: 1.测试环境为:windows server2003 和 oracle 10g. 2.2台服务器安装的程序目录一样,数据目录不 ...

最新文章

  1. webservice发送字符串
  2. XPath实例教程十四、following-sibling轴
  3. 使用Git将我的最后一个X提交一起压缩
  4. SimplifiedHibernate:简化了的Hibernate
  5. Linux 火狐浏览器安装Flash插入
  6. kettle将多个文件压缩_如何使用WinRAR将一个大文件压缩成多个小的压缩包
  7. 准备写一个Ibatisnet开发指南
  8. php 安装redis数据库,Linux下安装Redis以及phpredis模块
  9. 解决VC不包含stdint.h头文件问题
  10. 人生苦短python作伴_“人生苦短,我用Python”
  11. String去重方法
  12. vue.js点击按钮导出_怎样安装vuejs devtools助力vuejs高效开发
  13. php调京东联盟接口,使用京东联盟API获取自定义促销链接
  14. 阿里巴巴正式宣布5.4亿现金战略投资中国万网
  15. 关于宋宝华linux驱动学习视频的读后感
  16. 菜菜的刷题日记 | 215. 数组中的第K个最大元素
  17. Keep It Simple and Stupid是什么意思
  18. 极值点、驻点、拐点、关系点
  19. 产品周报第27期|会员新增拉黑用户权益;CSDN APP V5.1.0版本发布……
  20. detach分片表非常慢的一个案例

热门文章

  1. 在Apworks数据服务中使用基于Entity Framework Core的仓储(Repository)实现
  2. DDD理论学习系列(9)-- 领域事件
  3. 一步步学习EF Core(2.事务与日志)
  4. dotnetConf 2016 线上虚拟大会
  5. ubuntu 以太网已连接但是无法联网_工业以太网有多“牛X”?两个案例告诉你
  6. [转]《吐血整理》系列-顶级程序员工具集
  7. 嵌入式开发linux工具,嵌入式Linux开发入门之MfgTool工具的使用
  8. mysql mgr简介_MySQL Group Replication(MGR)使用简介与注意事项
  9. linux把2块盘挂到一个分区,linux系统如何挂载第二块硬盘
  10. python mssql github_GitHub上最热门的开源项目都在这里了