加入收藏 | 设为首页 | 会员中心 | 我要投稿 泰州站长网 (https://www.0523zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > 点评 > 正文

Oracle的null和空串【一切有为法,如梦幻泡影 】

发布时间:2022-08-25 20:10:14 所属栏目:点评 来源:
导读: drop table x purge;create table x (id number,name varchar(100));insert into x values (1,' ');insert into
drop table x purge;create table x (id number,name varchar(100));insert into x values (1,' ');insert into x values (2,'');insert into x values (3,'a');insert into x values (4,null);commit;col name for a20set linesize 300select * from x;

Oracle 认为''和null是等价的

coalesce判断逻辑正确,2和4是null所以返回xxxxxx 

因为'' == null ,所以没人任何值等于'' 或(没有任何值等于null)



SELECT decode(length(name),NULL,0,LENGTH(name)) ,length(name),dump(name),dump(name,16)FROM x;


在Oracle的内置函数中,大部分函数如果有null的参与,其结果也为null;

select substr(null,1,2) as str from dual;select instr(null,'a',1,2) as str from dual;select round(null,2) as str from dual;select to_char(null) as str from dual;select to_number(null) as str from dual;

如上语句,它们执行并不会报错,它们有结果。但执行后得到的都为null。

在oracle数据库中,不论是任何运算,只要有null参与,最后的结果一定是null。

select 10*null as num from dual;select 10+null as num from dual;select 10-null as num from dual;select 10/null as num from dual;

如上语句在oracle中,执行得到结果最后都为null。

不止是算数运算,在字符是否相等的比较中,有null的参与也是不一样的。

select case when 'abcd'=null then 1 else 0 end num from dual;select case when 'abcd'<>null then 1 else 0 end num from dual;select case when 'abcd'>null then 1 else 0 end num from dual;select case when 'abcd'<null then 1 else 0 end num from dual;

如上,当一个字符串与null作比较时,无论是等于,不等于,大于还是小于。其结果都是不成立的。后输出的值都是0。

(编辑:泰州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章