【问题标题】:unable add case condition inside a where clause in oracle无法在 oracle 的 where 子句中添加 case 条件
【发布时间】:2019-10-09 10:20:12
【问题描述】:

我有一个过程,我初始化变量i:=0,每次循环运行时我都会递增。我需要在i:=0i>0 时返回一个条件

我写的查询

Select ID from table 
where
case when i=0
then time <=end_time
when i>0
then time>start_time and time <=end_time

完全可以得到应该做的事情。

【问题讨论】:

  • 我相信 case 语句应该给出一个表达式的结果,或者换句话说,你的 case 语句的结果应该与某个东西而不是一个条件本身进行比较。
  • @RamaSh 是的,整个问题是我如何将其包含在 where 子句中?

标签: oracle case where-clause


【解决方案1】:

更改或声明:

 Select ID from table 
 where time <=end_time
 And (i<=0 or time>start_time) 

【讨论】:

    【解决方案2】:

    我认为在这种情况下,您可以重写您的查询,而不是使用 case 语句:-

    Select ID from table 
    where (i=0 and time <=end_time)
       or (i>0 and (time>start_time and time <=end_time));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      相关资源
      最近更新 更多