null和空字符串在oracle和postgresql中的不同
PostgreSQL的NULL是一个术语,用来代表一个缺失值。而’'是空字符串。举一个可能不太恰当的例子,null就类似于考生没有参加考试,而空值就类似考生参考考试但没有得分。
在postgresql中,空字符串与null是不同的;而在oracle中,空字符串与null相同。
在postgresql中测试:
#建表并插入数据
create table null_test (name varchar(10),adress varchar(10));
#adress字段插入为空值
insert into null_test values('a','');
#adress字段插入为null
insert into null_test(name) values('b');
select * from null_test;
name | adress
------+--------
a |
b |
select * from null_test where adress is null;
name | adress
------+--------
b |
#COALESCE函数返回它的第一个非null参数的值,检索数据时用缺省值替换null值
select name,COALESCE(adress,'c') as adress from null_test;
name | adress
------+--------
a |
b | c
在oracle中测试:
#建表并插入数据
create t