原生的PG 对于 '' 和 null 认为是不同值:空值 和不确定值;而oracle 认为二者都是不确定的值。KingbaseES 为了兼容Oracle,增加了参数ora_input_emptystr_isnull,用于控制 '' 和 null 的比较。

一、Oracle null and '' 比较

SQL> create table t1(id number,name varchar(9));

Table created.

SQL> insert into t1(id) values(1);

1 row created.

SQL> insert into t1 values(2,'');    --注意,中间没有空格。有空格就不是null

1 row created.

SQL> insert into t1 values(3,null);

1 row created.

SQL> select * from t1 where name is null;

        ID NAME
---------- ---------
1
2
3 SQL> select * from t1 where name=''; no rows selected SQL> select length(name) from t1; LENGTH(NAME)
------------ SQL>

可以看到,不管插入 null or '',Oracle 都看做 null。

二、KingbaseES

1、ora_input_emptystr_isnull=off

test=# show ora_input_emptystr_isnull;
ora_input_emptystr_isnull
---------------------------
off
(1 row)
test=# create table t1(id number,name varchar(9));
CREATE TABLE
test=# insert into t1(id) values(1);
INSERT 0 1
test=# insert into t1 values(2,'');
INSERT 0 1
test=# insert into t1 values(3,null);
INSERT 0 1
test=# select * from t1 where name is null;
id | name
----+------
1 |
3 |
(2 rows) test=# select * from t1 where name='';
id | name
----+------
2 |
(1 row) test=# select id,length(name) from t1;
id | length
---+--------
1 |
2 | 0
3 |
(3 rows)

结论:当ora_input_emptystr_isnull=off时,null 和 '' 实际不同的。

在数据插入后,将参数改成on,看下查询的不同结果:

test=# show ora_input_emptystr_isnull;
ora_input_emptystr_isnull
---------------------------
on
(1 row) test=# select * from t1 where name=''; --这个也没结果,这个数据“丢失“了
id | name
----+------
(0 rows) test=# select * from t1 where name is null;
id | name
----+------
1 |
3 |
(2 rows) test=# select id,length(name) from t1;
id | length
----+--------
1 |
2 | 0
3 |
(3 rows)

结论:当数据保存到数据库时,会根据参数ora_input_emptystr_isnull 保存为不同格式,后续的参数修改不影响已存储的数据。

2、ora_input_emptystr_isnull=on

test=# show ora_input_emptystr_isnull;
ora_input_emptystr_isnull
---------------------------
on
(1 row) test=# drop table t1;
DROP TABLE
test=# create table t1(id number,name varchar(9));
CREATE TABLE
test=# insert into t1(id) values(1);
INSERT 0 1
test=# insert into t1 values(2,'');
INSERT 0 1
test=# insert into t1 values(3,null);
INSERT 0 1
test=# select * from t1 where name='';
id | name
----+------
(0 rows) test=# select * from t1 where name is null;
id | name
----+------
1 |
2 |
3 |
(3 rows) test=# select id,length(name) from t1;
id | length
----+--------
1 |
2 |
3 |
(3 rows)

将参数改为off ,看下执行结果

test=# set ora_input_emptystr_isnull=off;
SET
test=# select * from t1 where name is null;
id | name
----+------
1 |
2 |
3 |
(3 rows) test=# select * from t1 where name='';
id | name
----+------
(0 rows)

结论:将参数改为off后,执行结果不变。

注意:由于参数 ora_input_emptystr_isnull不同设置,会修改实际的数据存储,为了保证数据不发生“丢失”,建议用户在系统初始化后就确定参数 ora_input_emptystr_isnull 的值,避免后续数据入库后再去修改参数。

参数 ora_input_emptystr_isnull 对于数据存储的影响的更多相关文章

  1. 讨论关于RAID以及RAID对于存储的影响

    定义及作用 RAID是Redundent Array of Inexpensive Disks的缩写,直译为“廉价冗余磁盘阵列”,也简称为“磁盘阵列”.后来RAID中的字母I被改作了Independe ...

  2. Kafka session.timeout.ms heartbeat.interval.ms参数的区别以及对数据存储的一些思考

    Kafka session.timeout.ms heartbeat.interval.ms参数的区别以及对数据存储的一些思考 在计算机世界中经常需要与数据打交道,这也是我们戏称CURD工程师的原因之 ...

  3. 数据存储之 SharedPreference 共享参数 (转)

        在上一讲中,我们学习了如何将数据存储在SD卡中[数据存储之File文件存储 [即SD卡的写入与读取]],这是一种存储方式,这一讲我们来学习一下使用SharedPreferences存储数据. ...

  4. android 开发-数据存储之共享参数

    android提供5中数据存储方式 数据存储之共享参数 内部存储 扩展存储 数据库存储 网络存储  而共享存储提供一种可以让用户存储保存一些持久化键值对在文件中,以供其他应用对这些共享参数进行调用.共 ...

  5. PCTUSED和PCTFREE对数据操作的影响

    1概念理解 首先PCTUSED和PCTFREE都是针对数据块的存储属性,单位都是%.其中PCTFREE决定了数据块什么时候从free list中移除,系统就不可以再往该数据块中插入数据,对于数据块中已 ...

  6. 智能合约语言 Solidity 教程系列4 - 数据存储位置分析

    写在前面 Solidity 是以太坊智能合约编程语言,阅读本文前,你应该对以太坊.智能合约有所了解, 如果你还不了解,建议你先看以太坊是什么 这部分的内容官方英文文档讲的不是很透,因此我在参考Soli ...

  7. CSAPP-过程调用,数据存储,缓冲区溢出

    程序编译: 1.预处理阶段: 1.文件包含:将#include扩展成文件正文 2.条件编译:根据#if和#ifdef将程序的某部分排除或者包含 3.宏展开:将出现宏引用的地方展开成相应的宏 2.编译阶 ...

  8. H5本地存储详细使用教程(localStorage + JSON数据存储应用框架)

    一.Web Storage教程 1.概述: 对于Web Storage来说,实际上是Cookies存储的进化版.如果了解Cookie的人几乎一看Web Storage就会用,如果你从来没用过没了解过C ...

  9. Hashtable数据存储结构-遍历规则,Hash类型的复杂度为啥都是O(1)-源码分析

    Hashtable 是一个很常见的数据结构类型,前段时间阿里的面试官说只要搞懂了HashTable,hashMap,HashSet,treeMap,treeSet这几个数据结构,阿里的数据结构面试没问 ...

  10. ubuntu14.04 rabbitmq安装与使用 --修改RabbitMQ数据存储位置

    参考:https://blog.csdn.net/tianjiewang/article/details/58383062 说明: ubuntu14.04   rabiitmq 默认 安装路径 /va ...

随机推荐

  1. docker 常用命令 快捷命令

    一.查询节点 docker ps -a 二.docker重启停止 systemctl restart docker systemctl stop docker docker restart * 三.一 ...

  2. golang常用库:gorilla/mux-http路由库使用

    golang常用库:gorilla/mux-http路由库使用 golang常用库:配置文件解析库/管理工具-viper使用 golang常用库:操作数据库的orm框架-gorm基本使用 一:gola ...

  3. 2021-07-01 原生js获取文件数据

    原理 手动用js创建一个type为file的DOM元素. 在读取到数据后,清空手动创建的DOM元素.返回得到的Promise类型的文件数据files. const getFilesPromise = ...

  4. Kotlin return@xxx 的坑

    Kotlin Return 到标签 先看例子: (1..5).forEach { if (it == 3) { return@forEach } println(it) } println(" ...

  5. 记一个 Andorid 生成文件失败的bug

    Android生成文件失败:java.lang.IllegalStateException:Failed to build unique file: /storage/emulated/0/... 1 ...

  6. 【Azure Redis 缓存】Azure Redis加入VNET后,在另一个区域(如中国东部二区)的VNET无法访问Redis服务(注:两个VNET已经结对,相互之间可以互ping)

    问题描述 为了保护Redis资源,把它与VNET集成后,实现只能通过VNET内网访问.在东二的区域中部署两个Redis服务后,发现一个奇怪的现象:东1区中的VM资源通过全局对等互联(Peering)实 ...

  7. 【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?

    问题描述 使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢? Microsoft Antimalware for Azure is ...

  8. Nebula Graph 源码解读系列 | Vol.02 详解 Validator

    整体架构 Nebula Graph Query Engine 主要分为四个模块,分别是 Parser.Validator.Optimizer 和 Executor. Parser 完成对语句的词法语法 ...

  9. 一文读懂图数据库 Nebula Graph 访问控制实现原理

    摘要:数据库权限管理对大家都很熟悉,然而怎么做好数据库权限管理呢?在本文中将详细介绍 Nebula Graph 的用户管理和权限管理. 本文首发 Nebula Graph 博客:https://neb ...

  10. Java 继承成员变量和继承方法的区别

    1 package com.bytezreo.duotai3; 2 3 /** 4 * 5 * @Description 继承成员变量和继承方法的区别 6 * @author Bytezero·zhe ...