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

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    记事本+hhc生成CHM
    在Delphi里实现[int map string]对
    U盘插入拔出提示
    Delphi研发笔试试卷 我的小解
    Excel也能用SQL查询
    访问JAVA中的字段(jfieldID)
    调用JAVA方法
    缓存字段ID和方法ID
    JNI引用
    访问数组(JNI)
  • 原文地址:https://www.cnblogs.com/tracy/p/1785226.html
Copyright © 2011-2022 走看看