执行除法的时候,为什么输出结果为空,而不是18啊:select 1800/(select case
                       when sum(t.nonenum) = '' then 100
                       when sum(t.nonenum) = 0 then 100
                  else 100 end
                from T_SEARCHNONE_COUNT@TO_31 t
               where t.staffno = '7449'
                 and t.logdate >= to_date('2013-3-27', 'yyyy-mm-dd')
                 and t.logdate < to_date('2013-3-28', 'yyyy-mm-dd'))
                 
            Rate
  from dual w;
oracle除法

解决方案 »

  1.   

    你这个子查询无论如何都应该返回100的,唯一的可能是,子查询没有符合条件的记录,另外  when sum(t.nonenum) = '' 这个写法有问题,应该写成  when sum(t.nonenum) is null
      

  2.   

    select 1800/null Rate from dual w;返回null有问题吗?
      

  3.   

    恩,1楼是正解。
    select 1800/(select case
                           when sum(t.nonenum) is null then 100
                           when sum(t.nonenum) = 0 then 100
                      else 100 end
                    from T_SEARCHNONE_COUNT@TO_31 t
                   where t.staffno = '7449'
                     and t.logdate >= to_date('2013-3-27', 'yyyy-mm-dd')
                     and t.logdate < to_date('2013-3-28', 'yyyy-mm-dd'))
                     
                Rate
      from dual w;
     你的查询结果为空,就是因为where条件没有符合数据,而用到了case when sum(t.nonenum) = '' then 100 导致  结果不是期待的100 而是null。    测试一下明确了。     select case when sum(null) = '' then 100 end from dual; 返回null;
         select case when sum(null) is null then 100 end from dual; 返回100;    还有就是对一些查询有疑问的时候可以通过dual表测试一下 ,特别是涉及null的时候,希望能帮到你,好运。