1

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

有人可以帮我解决我所缺少的吗?

4

2 回答 2

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 中无效。

于 2012-02-21T02:25:15.763 回答
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 函数。

于 2012-02-21T02:25:57.667 回答