zoukankan      html  css  js  c++  java
  • Where clause problem in Oracle 8i Can you "Where case when then..."

    To begin with the CASE expression - the key point is that CASE is an expression, not a statement - it has to return a value. Your CASE looks like this:

    Code:

    where 
    case
      When d = 2 then o.adddte between date1 and date2
      when d = 3 then o.adddte between date3 and date4
      when d IN (1, 4, 6, 5, 7) then o.adddte between date5 and date6
    end

    This is incorrect use of a CASE. In fact, you could be using OR:

    Code:

    where 
      (  ( d = 2 and o.adddte between date1 and date2 )
      or (d = 3 and o.adddte between date3 and date4)
      or (d IN (1, 4, 6, 5, 7) and o.adddte between date5 and date6)
      )

    To use CASE, your WHERE clause would have to be:

    Code:

    where o.adddte between
      case
        When d = 2 then date1
        when d = 3 then date3
        else date5
      end
    and 
      case
        When d = 2 then date2
        when d = 3 then date4
        else date6
      end

    The other problem is the invalid expressions in your SQL like this one:
    to_date ('trunc(sysdate-4) 15:00', 'dd/mm/yyyy hh24:mi')
    This should be:
    to_date(to_char(trunc(sysdate-4),'dd/mm/yyyy')||' 15:00', 'dd/mm/yyyy hh24:mi')
    or more simply:
    trunc(sysdate-4)+15/24

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    iOS 时区问题总结 NSTimeZone
    项目中图片问题
    支付宝支付相关问题汇总
    算法时间计算:logA(N)与O(n)
    UE4 AR开发笔记
    UE4 PostProcessVolume笔记
    cpp typename关键字
    UE4 二维相关
    ATOM基础教程一使用前端插件emmet(16)
    监听浏览器返回上一页
  • 原文地址:https://www.cnblogs.com/tracy/p/1785226.html
Copyright © 2011-2022 走看看