首页 > 解决方案 > Oracle SQL 中 CASE 中的“缺少关键字”

问题描述

CASEwhere子句中有这个,但是当我尝试保存时,出现“缺少关键字”错误。这样做的目的是检查是否设置a.term_date添加null条件,反之亦然。:prm_datenot between b.date and c.date

代码如下:

and ( 1 = CASE
          WHEN a.term_date is null then :prm_date between b.date and c.date
          ELSE :prm_date not between b.date and c.date 
          END )

我不太确定这是否是最好的方法。

:prm_date 是用户输入的日期参数

标签: sqloracle

解决方案


我想你想要:

and (
    (a.term_date is null and :prm_date between b.date and c.date)
    or
    :prm_date not between b.date and c.date
)

略微过多的空白用于增加清晰度。


推荐阅读