2012-02-28 55 views
4

以下是我的查詢。這是正義嗎?如何使用if語句中的條件?

SQL> select case when value in (1000) then null 
2 when user in ('ABC') then user 
3 when area in ('DENVER') then 
4 if value = 2000 then 'Service1' 
5 else value = 3000 then 'Service2' 
6 end if 
7 else null 
8 end as num_code from service_usoc_ref; 
if prin = 2000 then 'Omaha' 
* 
ERROR at line 4: 
ORA-00905: missing keyword 

請幫幫我。

+0

使用解碼聲明 – Maddy 2012-02-28 07:03:48

回答

6

您可以再舉一個例子,或者使用解碼(如@madhu建議):

select case 
    when value in (1000) then null 
    when user in ('ABC') then user 
    when area in ('DENVER') then 
    case when value = 2000 then 'Service1' 
     when value = 3000 then 'Service2' 
    end 
    else null 
    end as num_code 
from service_usoc_ref; 
3

這可以幫助你

select case when value in (1000) then null 
         when user in ('ABC') then user 
         when area in ('DENVER') then 
decode(value, 2000 , 'Service1',3000 , 'Service2', NULL) num_code 
from service_usoc_ref;