当前位置: 首页 > news >正文

参数 ora_input_emptystr_isnull 对于数据存储的影响

原生的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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

test=# show ora_input_emptystr_isnull;

ora_input_emptystr_isnull

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

off

(1 row)

test=#createtablet1(id number,namevarchar(9));

CREATETABLE

test=#insertintot1(id)values(1);

INSERT0 1

test=#insertintot1values(2,'');

INSERT0 1

test=#insertintot1values(3,null);

INSERT0 1

test=#select*fromt1wherenameisnull;

id |name

----+------

1 |

3 |

(2rows)

test=#select*fromt1wherename='';

id |name

----+------

2 |

(1 row)

test=#selectid,length(name)fromt1;

id | length

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

1 |

2 | 0

3 |

(3rows)

结论:当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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

test=# show ora_input_emptystr_isnull;

ora_input_emptystr_isnull

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

on

(1 row)

test=#droptablet1;

DROPTABLE

test=#createtablet1(id number,namevarchar(9));

CREATETABLE

test=#insertintot1(id)values(1);

INSERT0 1

test=#insertintot1values(2,'');

INSERT0 1

test=#insertintot1values(3,null);

INSERT0 1

test=#select*fromt1wherename='';

id |name

----+------

(0rows)

test=#select*fromt1wherenameisnull;

id |name

----+------

1 |

2 |

3 |

(3rows)

test=#selectid,length(name)fromt1;

id | length

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

1 |

2 |

3 |

(3rows)

将参数改为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 的值,避免后续数据入库后再去修改参数。

http://www.jsqmd.com/news/1218631/

相关文章:

  • 嵌入式SDRAM控制器配置实战:从寄存器手册到Linux驱动优化
  • Sqribble深度解析:面向非设计师的结构化电子书出版流水线
  • WinUI 3.0开发指南:现代Windows应用UI框架解析
  • 东莞专业 GEO 服务商推荐,高性价比本地 GEO 运营机构怎么选
  • 快慢指针巧解链表中间结点
  • Unity游戏模组框架BepInEx:从原理到实战的完整安装与配置指南
  • 反复过敏性鼻炎调理成健康消费新热点 牛初乳免疫补充路径引行业关注
  • 2026广元卫生间防水、外墙、地下室、楼顶渗漏、阳光房防水 选对服务商,售后无忧,告别房屋渗漏(一次维修,售后无忧) - 企业资讯
  • 嵌入式图像处理与GPU架构:TI OMAP平台ISP与SGX硬件配置实战
  • Windows任务栏透明美化终极指南:3种安装方式+5大效果模式全解析
  • Cordova跨平台开发:调试优化与发布全攻略
  • AM62L DDR控制器深度解析:模式寄存器与动态频率切换实战指南
  • Android Socket编程实战:TCP/UDP实现与优化
  • Objective-C中使用Protocol Buffers实现高效通信
  • 从零搭建压力测试监控环境:JMeter与Prometheus+Grafana实战指南
  • 嵌入式PRCM模块编程:从唤醒事件到电压控制的低功耗管理实践
  • TI高速USB OTG控制器高带宽同步传输与精细功耗管理实战
  • ARM嵌入式开发:从GPIO到国密算法的实践指南
  • 中山火炬DHL/FedEx/UPS国际快递代理哪家好13500091568 - 烟雾弥漫L
  • 电商可以没有专职运营,但不能没有一套进销存管住多平台库存——杭州服务商一线复盘
  • Selenium XPath元素定位:从原理到实战的完整指南
  • Fay与UE5超写实数字人开发:从AI驱动到实时渲染全链路实战
  • Linux服务器运维实战:从环境配置到自动化部署完整指南
  • 好心情:靠谱的恋爱关系修复心理教育机构
  • AM62L调试子系统ROM表手动入口寄存器配置与实战解析
  • 研发项目管理系统任务书
  • AM62L FSS模块ECC与OSPI寄存器配置与调试实战指南
  • 机器学习模型生产化落地:从Notebook到K8s的全链路工程实践
  • 前端水印技术实现与防护全解析
  • 深入解析AM62L调试子系统:ROM表、APBAP与AXIAP实战指南