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

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    build.gradle文件详解<转> 推荐
    openGL 环境配置
    手写 大整数
    FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)
    2.1 基本计数方法
    第7章 代码
    第7章 高级数据结构的编程实验
    3.3 字符串(1)
    2016_NENU_CS_3
    3.2 区间信息的维护与查询
  • 原文地址:https://www.cnblogs.com/tracy/p/1785226.html
Copyright © 2011-2022 走看看