select count(case when tid='' then 1 else 0 end) from   (select '' as tid  from dual)
返回1select count(*) from (select '' as tid   from dual) where tid=''
返回0
oracle

解决方案 »

  1.   

     tid='' 你的tid是空,而空的比较不能用=来比较,要用 is null 或者is not null比较select count(case when tid is null then 1 else 0 end) from   (select '' as tid  from dual)
      

  2.   

    正解
    select count(*) from (select '' as tid   from dual) where tid is null
      

  3.   

    when 问什么能识别这个条件,where为什么不行,我把两个例子放在一起就是想问这个?
      

  4.   

    第一个 CASE WHEN ..ELSE 那无论如何都或有一个记录 不是0 就是 1
    第二个 明显是没有记录,因为条件为FALSE了,   COUNT(*)自然就是0了
      

  5.   


    10:45:23 ChenZw> select nvl('','true') from dual;NVL(
    ----
    true已选择 1 行。已用时间:  00: 00: 00.01
      

  6.   

    研究了一下楼上的题目,也陷入困惑了.....如下:
    10:50:04 ChenZw> select nvl('',1) from dual;N
    -
    110:50:17 ChenZw> select nvl2('',1,-1) from dual;NVL2('',1,-1)
    -------------
               -1已选择 1 行。
    我的预期结果,两个都是1,但是上面的结果为什么不一样呢?
      

  7.   

    哦,我对nvl2的理解错误了... 返回exp3,而不是exp2 ,怪不得,谢谢