Reputation: 588
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.
Upvotes: 0
Views: 335
Reputation: 11
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!!!
Upvotes: 1
Reputation: 3118
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))
Upvotes: 1
Reputation:
where sale.op = 2
and ( (:stat = -11 and sale.type_id in (27, 28, 29))
or (:stat <> -11 and sale.type_id = 27)
)
Upvotes: 5
Reputation: 2500
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))
Upvotes: 1