where sale.op = 2
and ( (:stat = -11 and sale.type_id in (27, 28, 29))
or (:stat <> -11 and sale.type_id = 27)
)
Oracle - Case in where clause
Question
I am trying to execute a query in Oracle database. The query has case construction in where clause.
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
But I am getting the following error:
ORA-00907: missing right parenthesis.
In Derby SQL this works. Does anybody can help me? Thank you.
La solution
Autres conseils
You could also try without CASE, using simple operators AND and 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))
try this query:
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))
try this query
where
sale.op =2 and
((:stat = -11 and sale.type_id=any(27,28,29)) or
(:stat <> -11 and sale.type_id = 27))
It looks more clear!!!
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow