在select语句中,我想减去连接日期以确定OEM保修标志。我收到错误ORA-00920:无效的关系运算符。 我在这里缺少什么?
--OEM WARRANTY FROM MFG SERIAL AND RECV DATE
CASE WHEN TO_CHAR(a.RECV_DATE, 'MM/DD/YY') -
TO_CHAR(CASE
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'A' THEN '01'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'B' THEN '02'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'C' THEN '03'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'D' THEN '04'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'E' THEN '05'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'F' THEN '06'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'G' THEN '07'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'H' THEN '08'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'J' THEN '09'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'K' THEN '10'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'L' THEN '11'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'M' THEN '12'
ELSE 'FIRST CHAR OF MFG SERIAL INCORRECT' END
||'/' || SUBSTR(a.CARD_RECV_SERIAL_NBR, 10, 2) ||'/'|| SUBSTR(a.CARD_RECV_SERIAL_NBR, 2, 2)), 'MM/DD/YY')
> '365' THEN 'N' ELSE 'Y'
END AS "OEM WARR"
答案 0 :(得分:0)
您正在创建两个字符串(使用FileCopyUtils
),然后从另一个中减去一个,然后将您与字符串'365'进行比较?你如何从另一个中减去一个STRING?
您可能希望将这些内容设为TO_CHAR()
- 然后将差异与数字TO_DATE()
进行比较,而不是字符串365
。
答案 1 :(得分:0)
对我来说最明显的事情是当你真正想要减去日期时,试图减去字符串。也许是这样的:
CASE WHEN a.RECV_DATE -
TO_DATE(
CASE WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'A' THEN '01'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'B' THEN '02'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'C' THEN '03'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'D' THEN '04'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'E' THEN '05'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'F' THEN '06'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'G' THEN '07'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'H' THEN '08'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'J' THEN '09'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'K' THEN '10'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'L' THEN '11'
WHEN SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1) = 'M' THEN '12'
END || '/' || SUBSTR(a.CARD_RECV_SERIAL_NBR, 10, 2) ||'/'||
SUBSTR(a.CARD_RECV_SERIAL_NBR, 2, 2)), 'MM/DD/YY') > 365
THEN 'N' ELSE 'Y' END as "OWM WARR"
(未测试的)
至于错误消息,我不认为你可以在纯SQL上下文中执行此操作。这是PL / SQL程序的一部分吗?如果没有,那么您应该在WHERE子句中将数据限制为有效月份。
更紧凑:
CASE WHEN a.RECV_DATE -
TO_DATE(DECODE(SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1),
'A','01', 'B','02', 'C','03', 'D','04', 'E','05', 'F','06'
'G','07', 'H','08', 'J','09', 'K','10', 'L','11', 'M','12')
|| '/' || SUBSTR(a.CARD_RECV_SERIAL_NBR, 10, 2) ||'/'||
SUBSTR(a.CARD_RECV_SERIAL_NBR, 2, 2)), 'MM/DD/YY') > 365
THEN 'N' ELSE 'Y' END as "OWM WARR"
答案 2 :(得分:0)
--MANUFACTURER DATE
--DECODE MFG SERIAL MONTH
TO_DATE(DECODE(SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1),
'A','01', 'B','02', 'C','03', 'D','04', 'E','05', 'F','06',
'G','07', 'H','08', 'J','09', 'K','10', 'L','11', 'M','12')
|| '/' || SUBSTR(a.CARD_RECV_SERIAL_NBR, 10, 2) ||'/'||
SUBSTR(a.CARD_RECV_SERIAL_NBR, 2, 2), 'MM/DD/YYYY') AS "MFG DATE",
---------------------------------------------------------------------
--OEM WARRANTY FROM MFG SERIAL AND RECV DATE
CASE WHEN a.RECV_DATE -
TO_DATE(DECODE(SUBSTR(a.CARD_RECV_SERIAL_NBR, 1, 1),
'A','01', 'B','02', 'C','03', 'D','04', 'E','05', 'F','06',
'G','07', 'H','08', 'J','09', 'K','10', 'L','11', 'M','12')
|| '/' || SUBSTR(a.CARD_RECV_SERIAL_NBR, 10, 2) ||'/'||
SUBSTR(a.CARD_RECV_SERIAL_NBR, 2, 2), 'MM/DD/YYYY') > 365
THEN 'N' ELSE 'Y' END as "OEM WARR"
---------------------------------------------------------------------