尝试在Oracle中运行以下查询时出现ORA-00905: missing keyword
错误:
select distinct MONTH_ID
from DSS_MAIN.DIM_TIME a1
where Case When TO_CHAR(SYSDATE,'MM') < 3
Then TO_CHAR(a1.MONTH_START_DATE,'YYYYMM') Between (TO_CHAR(SYSDATE,'YYYY')-1)||'03' And TO_CHAR(SYSDATE,'YYYYMM')
Else TO_CHAR(a1.MONTH_START_DATE,'YYYYMM') Between TO_CHAR(SYSDATE,'YYYY')||'03' And TO_CHAR(SYSDATE,'YYYYMM')
End;
单个Between
条款工作正常,因此我假设Case
语法有问题。
有什么想法吗?
答案 0 :(得分:3)
试试这个:
SELECT DISTINCT MONTH_ID
FROM DSS_MAIN.DIM_TIME A1
WHERE TO_CHAR(A1.MONTH_START_DATE, 'YYYYMM')
BETWEEN CASE
WHEN TO_CHAR(SYSDATE, 'MM') < '03' THEN
(TO_NUMBER(TO_CHAR(SYSDATE, 'YYYY')) - 1) || '03'
ELSE
TO_CHAR(SYSDATE, 'YYYY') || '03'
END
AND TO_CHAR(SYSDATE, 'YYYYMM')
大小写返回一个值以供进一步使用,它对你使用它的方式没有用。