原生的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。二、KingbaseES1、ora_input_emptystr_isnulloff123456789101112131415161718192021222324252627282930313233test# show ora_input_emptystr_isnull;ora_input_emptystr_isnull---------------------------off(1 row)test#createtablet1(id number,namevarchar(9));CREATETABLEtest#insertintot1(id)values(1);INSERT0 1test#insertintot1values(2,);INSERT0 1test#insertintot1values(3,null);INSERT0 1test#select*fromt1wherenameisnull;id |name----------1 |3 |(2rows)test#select*fromt1wherename;id |name----------2 |(1 row)test#selectid,length(name)fromt1;id | length-----------1 |2 | 03 |(3rows)结论当ora_input_emptystr_isnulloff时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_isnullon123456789101112131415161718192021222324252627282930313233343536test# show ora_input_emptystr_isnull;ora_input_emptystr_isnull---------------------------on(1 row)test#droptablet1;DROPTABLEtest#createtablet1(id number,namevarchar(9));CREATETABLEtest#insertintot1(id)values(1);INSERT0 1test#insertintot1values(2,);INSERT0 1test#insertintot1values(3,null);INSERT0 1test#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_isnulloff; 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 对于数据存储的影响
原生的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。二、KingbaseES1、ora_input_emptystr_isnulloff123456789101112131415161718192021222324252627282930313233test# show ora_input_emptystr_isnull;ora_input_emptystr_isnull---------------------------off(1 row)test#createtablet1(id number,namevarchar(9));CREATETABLEtest#insertintot1(id)values(1);INSERT0 1test#insertintot1values(2,);INSERT0 1test#insertintot1values(3,null);INSERT0 1test#select*fromt1wherenameisnull;id |name----------1 |3 |(2rows)test#select*fromt1wherename;id |name----------2 |(1 row)test#selectid,length(name)fromt1;id | length-----------1 |2 | 03 |(3rows)结论当ora_input_emptystr_isnulloff时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_isnullon123456789101112131415161718192021222324252627282930313233343536test# show ora_input_emptystr_isnull;ora_input_emptystr_isnull---------------------------on(1 row)test#droptablet1;DROPTABLEtest#createtablet1(id number,namevarchar(9));CREATETABLEtest#insertintot1(id)values(1);INSERT0 1test#insertintot1values(2,);INSERT0 1test#insertintot1values(3,null);INSERT0 1test#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_isnulloff; 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 的值避免后续数据入库后再去修改参数。