KES数据库参数 ora_input_emptystr_isnull 使用详解
一、参数功能概述
ora_input_emptystr_isnull 是 KingbaseES (KES) 数据库中的一个兼容性参数,专门用于处理空字符串('')与 NULL 值的转换问题。该参数主要用于提高与 Oracle 数据库的兼容性。
数据库是oracle 模式时,参数ora_input_emptystr_isnull=on是为了兼容oracle 对于‘’作为null处理。
作用:控制是否将空字符串('')自动转换为 NULL 值
二、参数取值及含义
| 参数值 | 含义 |
|---|---|
| on | 开启功能,空字符串('')作为NULL处理(默认值) |
| off | 关闭功能,空字符串('')与NULL区分处理 |
三、参数查看方法
1. 查看当前参数设置
test=# SHOW ora_input_emptystr_isnull;
ora_input_emptystr_isnull
---------------------------
off
(1 行记录)

2. 通过系统视图查看
test=# SELECT name, setting, unit, short_desc
test-# FROM sys_settings
test-# WHERE name = 'ora_input_emptystr_isnull';
name | setting | unit | short_desc
---------------------------+---------+------+-------------------------------
ora_input_emptystr_isnull | off | | Convert empty string to null.
(1 行记录)

四、参数设置方法
1. 会话级设置(仅当前会话有效)
test=# SET ora_input_emptystr_isnull = on;
SET
test=# SHOW ora_input_emptystr_isnull;
ora_input_emptystr_isnull
---------------------------
on
(1 行记录)

2. 用户级设置(对指定用户永久生效)
test=# ALTER USER system SET ora_input_emptystr_isnull = on;
ALTER ROLE

3. 数据库级设置(对整个数据库生效)
test=# ALTER DATABASE test SET ora_input_emptystr_isnull = on;
ALTER DATABASE

4. 全局设置(修改配置文件)
修改 kingbase.conf 文件的最后位置,添加:
ora_input_emptystr_isnull = on
修改后需重启KES服务或reload重载文件生效(选择其中一个即可)。

五、参数使用示例 (判断值是否为空,要用 is null)
**1. 当参数设为off时 **
test=# SET ora_input_emptystr_isnull = off;
SET
test=# CREATE TABLE test_null (id int, name varchar(20));
CREATE TABLE
test=# INSERT INTO test_null VALUES (1, ''); -- 插入空字符串
INSERT 0 1
test=# INSERT INTO test_null VALUES (2, NULL); -- 插入NULL
INSERT 0 1
SELECT id, name, name IS NULL FROM test_null;
id | name | ?column?
----+------+----------
1 | | f <-- 空字符串不为NULL
2 | | t <-- 真实的NULL
(2 行记录)

2. 当参数设为on时(默认情况)
test=# SET ora_input_emptystr_isnull = on;
SET
test=# TRUNCATE TABLE test_null;
TRUNCATE TABLE
test=# INSERT INTO test_null VALUES (1, ''); -- 插入空字符串
INSERT 0 1
test=# INSERT INTO test_null VALUES (2, NULL); -- 插入NULL
INSERT 0 1
test=# SELECT id, name, name IS NULL FROM test_null;
id | name | ?column?
----+------+----------
1 | | t <-- 空字符串转为NULL
2 | | t <-- 真实的NULL
(2 行记录)

此测试数据库版本号为:V009R001C010

浙公网安备 33010602011771号