缺少一些parentehtesis

时间:2018-03-16 12:49:37

标签: oracle

处理下面的案例陈述,并不断收到错误的括号错误。有什么建议吗?

( CASE        
  WHEN  XBAND = 4 AND TBAND = 0 AND YBAND >= 2
 THEN 'A'
 END
 ELSE
 CASE
 WHEN  XBAND = 4 AND TBAND = 0 AND YBAND >= 3
 THEN 'B'
 END 
  END ) XYT_BAND

2 个答案:

答案 0 :(得分:2)

每个END表达式应该只有一个CASE。这应该有效:

 CASE        
   WHEN  XBAND = 4 AND TBAND = 0 AND YBAND >= 2
     THEN 'A'
   WHEN  XBAND = 4 AND TBAND = 0 AND YBAND >= 3
     THEN 'B'
   END XYT_BAND

如果你需要嵌套CASE表达式,那么:

 CASE        
   WHEN  XBAND = 4 AND TBAND = 0 AND YBAND >= 2
     THEN 'A'
   ELSE
     CASE
       WHEN  XBAND = 4 AND TBAND = 0 AND YBAND >= 3
       THEN 'B'
     END
   END XYT_BAND

答案 1 :(得分:1)

为了为每个条目生成多行,您可以使用union或更灵活的unpivot将列转置为行:

<强> demo

select id, xyt_band
  from (select id, 
               case when xband = 4 and yband = 0 and tband >= 2 then 'A' end c1, 
               case when xband = 4 and yband = 0 and tband >= 3 then 'B' end c2
          from t)
  unpivot (xyt_band for cx in (C1, C2))