2017-09-12 71 views
0

這段代碼有什麼問題?oracle中的case sql

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

看看在這個問題https://stackoverflow.com/questions/24249323/us ing-case-inside-where-clause – kzharas210

回答

1

case是一個返回值的表達式。並且case表達以end結束。而一個case表達式返回一個有效的類型。

也許你打算:

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

表達更簡單的方法邏輯,而case是:

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

但你可能真的打算:

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

謝謝...... Gordon Linoff其工作。 –