oracle NULL与''空字符串

oracle查询版本号

  1. select * from v$version;
  2. select * from product_component_version;
  3. SET SERVEROUTPUT ON; EXEC dbms_output.put_line( dbms_db_version.version );

oracle NULL与’'空字符串

  1. oracle中在可为null的字段上做逻辑关系运算要格外小心,如 <>,>,=,<,任何与null的运算结果都返回false.因此对于可能为null的字段运算判断要用 is null 来判断,或者使用函数nvl、decode处理后在判断,比如:where 字段名 is null 或者where nvl(字段名,0) = 0; 假设字段类型是数字
  2. Oracle中的空字符串基本上是被当成空NULL来处理的,例如:select nvl(’’,‘NULL’) from dual 返回’NULL’,select 1 from dual where ‘’ is null 返回1。
  3. ‘’ = ''返回的结果为假,而NULL = ‘‘将返回结果为假;’’ is NULL 不报错,而NULL is ‘’ 将发生找不到关键字NULL的错误
select case when ''='' then 'true' else 'false' end from dual; --返回false
select case when NULL=NULL then 'true' else 'false' end from dual; --返回false
select case when NULL='' then 'true' else 'false' end from dual; --返回false
select case when '' IS NULL then 'true' else 'false' end from dual; --返回true
select case when NULL IS NULL then 'true' else 'false' end from dual; --返回true
select case when '' IS '' then 'true' else 'false' end from dual; --提示缺失NULL关键字
select case when NULL IS '' then 'true' else 'false' end from dual; --提示缺失NULL关键字
  1. 判断两个字符串是否相等的函数
create or replace function isequal(var1 in varchar2, var2 in varchar2)
 return number -- 0:不等 1:相等 -1:错误
 is
begin
  if (var1 is null and var2 is null or
     var1 is not null and var2 is not null and var1 = var2) then
    return 1;
  else  
    return 0;
  end if;
exception
  when others then
    return - 1;
end;  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值