1

我不确定这一系列 case 语句有什么问题。我在网上看过,语法似乎是正确的,但我得到了错误缺失关键字。任何帮助将非常感激!

CASE 
when A = '1' then
         when sequence_number = 5 then 9
         when sequence_number = 6 then 9
         end
 when A = '2' then
       when sequence_number = 5 then 9
       when sequence_number = 6 then 9
       end
  when A = '3' then
        when sequence_number =7 then 9
        when sequence_number =8 then 9
        end
else T.number
end as number 
4

3 回答 3

2

最简单的选择似乎是:

 case 
   when (A in (1,2) and sequence_number in (5,6)) or
        (A in (3  ) and sequence_number in (7,8))
   then 9
   else t.number
 end
于 2013-03-12T22:56:11.723 回答
2

您要么需要CASE在每个分支中添加第二条语句,要么需要组合条件

CASE 
when A = '1' and sequence_number = 5 then 9
when A = '1' and sequence_number = 6 then 9
when A = '2' and sequence_number = 5 then 9
...
else T.number
end as number 

或者

CASE 
when A = '1' then
         case when sequence_number = 5 then 9
              when sequence_number = 6 then 9
         end
when A = '2' then
       case when sequence_number = 5 then 9
            when sequence_number = 6 then 9
       end
when A = '3' then
        case when sequence_number =7 then 9
             when sequence_number =8 then 9
        end
else T.number
end as number 
于 2013-03-12T20:40:29.220 回答
0

@mikeb 是正确的 - 你需要一个额外的 CASE。

我在测试时也遇到了Number列问题;只是猜测,但也许甲骨文将其作为保留字窒息?如果您像我一样遇到ORA-01747: invalid user.table.column, table.column, or column specification异常,请将其更改为类似Numor TheNumber

这是更新的案例:

CASE
when A = '1' then
       case
       when sequence_number = 5 then 9
       when sequence_number = 6 then 9
       end
when A = '2' then
       case
       when sequence_number = 5 then 9
       when sequence_number = 6 then 9
       end
when A = '3' then
       case
       when sequence_number =7 then 9
       when sequence_number =8 then 9
       end
else T.number
end as number
于 2013-03-12T20:42:25.117 回答