0

我的来源中有一张桌子。IT 有 2 列 period(varchar) 和 Center(varchar)。中心具有以下值 L150 L180 L352 并且期间具有 NULLS。

我正在尝试运行此查询

select TIP.PERIOD
  from SCOTT.TIP
 where (1=1)
       and (
         CASEWHEN TIP.CENTRO IN ('L150','L180','L358')
             THEN TIP.PERIOD = 'C'
             ELSE TIP.PERIOD = 'D'
              END)

但我收到无效的关系运算符错误。可能是什么原因?

谢谢!

4

4 回答 4

1

这是错误的

CASEWHEN 

改变它哟

CASE WHEN 



select TIP.PERIOD
   from SCOTT.TIP  where (1=1) and (
   TIP.PERIOD = CASE WHEN TIP.CENTRO IN ('L150','L180','L358')
   THEN TIP.PERIOD = 'C'
   ELSE TIP.PERIOD = 'D'
   end)
于 2013-03-20T18:29:01.753 回答
0

So, tip.period is a null value that you're "defining" during the query?

SELECT 
    CASE 
        WHEN TIP.CENTRO IN ('L150','L180','L358')
        THEN 'C'
        ELSE 'D'
    END as period
from scott.tip
于 2013-03-20T18:32:53.913 回答
0
select TIP.PERIOD
from SCOTT.TIP  
where 
  TIP.PERIOD = 
    CASE
      WHEN TIP.CENTRO IN ('L150','L180','L358') THEN 'C'
      ELSE 'D'
    end
于 2013-03-20T18:33:53.227 回答
0

对于完整的 Oracle 语法,您需要以下内容:

select TIP.PERIOD
from SCOTT.TIP
where (1=1) and (
 TIP.PERIOD =
   CASE WHEN TIP.CENTRO IN ('L150','L180','L358') THEN 'C' ELSE 'D' END
于 2013-03-20T18:36:14.230 回答