2014-01-22 70 views
0

我想在Oracle数据库中执行查询。该查询在where子句中有案例构造。Oracle - 案例在哪里条款

where 
    sale.op = 2 and 
     case when (:stat = -11) then (sale.type_id = 27 or sale.type_id = 28 or sale.type_id = 29) 
    else 
    (sale.type_id = 27) 
    end 

但我收到以下错误:

ORA-00907: missing right parenthesis.

在德比SQL这个工程。有人可以帮助我吗? 谢谢。

+0

CASE评估条件并返回一个“表达式”,需要使用运算符评估某个值/列。 – Incognito

回答

5
where sale.op = 2 
and ( (:stat = -11 and sale.type_id in (27, 28, 29)) 
     or (:stat <> -11 and sale.type_id = 27) 
    ) 
1

尝试此查询:

where 
    sale.op = 2 and 
     ((:stat = -11 and (sale.type_id = 27 or sale.type_id = 28 or sale.type_id = 29)) 
     or (:stat <> -11 and sale.type_id = 27)) 
1

你也可以和尝试没有情况下,使用简单的操作符和OR:

where 
    sale.op = 2 and ((:stat = -11 and (sale.type_id = 27 or sale.type_id = 28 or sale.type_id = 29)) 
     OR (:stat <> -11 and sale.type_id = 27)) 
1

尝试此查询

where 
    sale.op =2 and 
    ((:stat = -11 and sale.type_id=any(27,28,29)) or 
     (:stat <> -11 and sale.type_id = 27)) 

它看起来更清晰!