Oracle 10g:select语句中的CASE(ORA-00936错误)

时间:2012-02-21 02:11:42

标签: oracle10g ora-00936

我正在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:缺少表达

有人可以帮助解决我错过的问题吗?

2 个答案:

答案 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函数。