带有表达式的case语句抛出错误

时间:2016-03-01 05:49:02

标签: sql oracle case

我试图在Oracle中执行以下语句,但它会抛出错误。请帮助。

select a.PHONE_NUMBER, 
CASE a.PHONE_NUMBER
WHEN '2262070200' THEN '2262070200'
WHEN a.PHONE_NUMBER = '2262070201' OR a.PHONE_NUMBER = '2262070202' THEN '2ND'
END
from temp_a a;

错误:

  

ORA-00905:缺少关键字

Temp_a中的数据

2262070200
2262070201
2262070202
2262070203
2262070204
2262070205
2262070206
2262070223
2262070224
2262070225

3 个答案:

答案 0 :(得分:2)

您的查询应该是这样的

select a.PHONE_NUMBER, 
CASE 
WHEN a.PHONE_NUMBER = '2262070200' THEN '2262070200'
WHEN a.PHONE_NUMBER = '2262070201' OR a.PHONE_NUMBER = '2262070202' THEN '2ND'
END
from temp_a a;

答案 1 :(得分:0)

我发现了错误

声明应为

select a.PHONE_NUMBER,
CASE 
WHEN a.PHONE_NUMBER ='2262070200' 
 THEN '2262070200' 
WHEN a.PHONE_NUMBER = '2262070201' OR a.PHONE_NUMBER = '2262070202' 
 THEN '2ND' 
END 
from temp_a a;

答案 2 :(得分:0)

试试这个:

SELECT a.PHONE_NUMBER,
  CASE 
    WHEN a.PHONE_NUMBER = '2262070200'
    THEN '2262070200'
    WHEN a.PHONE_NUMBER = '2262070201'  OR a.PHONE_NUMBER   = '2262070202'
    THEN '2ND'
  END
FROM temp_a a;