我的源码中有一张表。 IT有2列句点(varchar)和中心(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)
但是我得到了无效的关系运算符错误。可能是什么原因?
谢谢!
答案 0 :(得分: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)
答案 1 :(得分:0)
那么,tip.period是一个在查询期间“定义”的空值?
SELECT
CASE
WHEN TIP.CENTRO IN ('L150','L180','L358')
THEN 'C'
ELSE 'D'
END as period
from scott.tip
答案 2 :(得分:0)
select TIP.PERIOD
from SCOTT.TIP
where
TIP.PERIOD =
CASE
WHEN TIP.CENTRO IN ('L150','L180','L358') THEN 'C'
ELSE 'D'
end
答案 3 :(得分: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