我正在Oracle 10g中执行此语句。
select CASE Math WHEN BETWEEN 90 AND 100 THEN 'A'
WHEN BETWEEN 80 AND 90 THEN 'B'
WHEN BETWEEN 0 AND 80 THEN 'C'
ELSE 'Invalid score' END
from score
但是我收到以下错误
ORA-00936:缺少表达
有人可以帮助解决我错过的问题吗?
答案 0 :(得分:2)
在SQL语句中,CASE
语句需要类似于
SELECT CASE WHEN math BETWEEN 90 AND 100
THEN 'A'
WHEN math BETWEEN 80 AND 90
THEN 'B'
WHEN math BETWEEN 0 AND 80
THEN 'C'
ELSE 'Invalid Score'
END
FROM score
CASE variable WHEN
语法在PL / SQL中有效,但在SQL中无效。
答案 1 :(得分:1)
而不是使用条件我会这样做:
select CASE WHEN math BETWEEN 90 AND 100 THEN 'A'
WHEN math BETWEEN 80 AND 90 THEN 'B'
WHEN math BETWEEN 0 AND 80 THEN 'C'
ELSE 'Invalid score' END
from score
如果没有前面的变量,我认为Oracle不喜欢BETWEEN函数。