Liton Biswas
Liton Biswas

Reputation: 39

Case in oracle sql

What is the wrong with this code?

select emp_id, emp_name 
from emp 
where case  when :emp.designation_id = '008' then designation_id = '003'

Upvotes: 0

Views: 55

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269503

case is an expression that returns a value. And a case expression ends with end. And a case expression returns a valid type.

Perhaps you intend:

select emp_id, emp_name 
from emp
where designation_id = (case when :emp.designation_id = '008' then designation_id = '003' end);

A simpler way to express this logic without case is:

where :emp.designation_id = '008' and designation_id = '003'

But you probably really intend:

where (:emp.designation_id = '008' and designation_id = '003') or
      (:emp.designation_id <> '008' and designation_id = :emp.designation_id)

Upvotes: 1

Related Questions