ITeye博客

一个奇怪的现象

icyheart · 2009-08-07 17:58 · Oracle · SQL Server · SQL · Oracle · Markdown

在sql server和oracle中有这样一个奇怪的现象:

在sql server中:

select case when '1'<>' ' then 'ok' else 'no' end
select case when '1'<>'' then 'ok' else 'no' end

 

这两条语句的返回值都为OK

但是,在oracle中:

select case when '1'<>'' then 'ok' else 'no' end from dual;

 

这个返回值为no

select case when '1'<>' ' then 'ok' else 'no' end from dual;

 

这个返回值为OK

这种现象该怎么解释呢?

评论(3)

  1. #3 楼 · orangehome · 2009-09-27 16:28

    oracle里''表示null,null不是等于且不是不等于其他任何值 (有点拗口……) ^_^

  2. #2 楼 · icyheart · 2009-08-11 08:44
    select case when '1'<>nvl('',' ') then 'ok' else 'no' end from dual;
    
  3. #1 楼 · 刘梦龙 · 2009-08-10 16:18

    oracle中'' 和' '是两个不同概念的东西,前者代表null,后者代笔一个空格,null不能直接拿来和字符做对比,应该nvl后再做比较 sql server中两者意思一样 所以是可以的

评论功能维护中,当前仅展示历史评论。