运行此更新命令时遇到一些麻烦。我一直收到错误消息“ORA-00933:SQL命令未正确结束”。任何人都可以协助我帮助我做到这一点吗?这就是我现在所拥有的一切?
谢谢, 乔治
UPDATE A
SET EARLIEST_STARTDATE = CASE WHEN (DATE_SUBMITTED < TO_DATE('01/04/' || EXTRACT(YEAR FROM ADD_MONTHS(DOB, 24)),'DD/MM/YYYY'))
THEN TO_DATE('01/04/' || EXTRACT(YEAR FROM ADD_MONTHS(DOB, 24)),'DD/MM/YYYY')
ELSE TO_DATE(DATE_SUBMITTED,'DD/MM/YY') END
FROM TABLE1 A
INNER JOIN TABLE2 C on A.ID = C.ID
WHERE (EARLIEST_STARTDATE IS NULL) AND
(A.WS_ELIGIBILITY_STATUS = 1) AND
(A.CLAIM_ADD_CRITERIA_FLAG = 'N' OR A.CAF = 'Y' or A.CCA_CODE = 'SC' AND A.CLAIM_ADD_CRITERIA_FLAG = 'Y') AND
(ADD_MONTHS(C.DOB, 24) BETWEEN TO_DATE('01/01/' || EXTRACT(YEAR FROM ADD_MONTHS(C.DOB, 24)),'DD/MM/YYYY') AND TO_DATE('31/03/' || EXTRACT(YEAR FROM ADD_MONTHS(C.DOB, 24)),'DD/MM/YYYY'))
答案 0 :(得分:0)
UPDATE A
SET EARLIEST_STARTDATE =
(SELECT
CASE WHEN (DATE_SUBMITTED < TO_DATE('01/04/' || EXTRACT(YEAR FROM ADD_MONTHS(DOB, 24)),'DD/MM/YYYY'))
THEN TO_DATE('01/04/' || EXTRACT(YEAR FROM ADD_MONTHS(DOB, 24)),'DD/MM/YYYY')
ELSE TO_DATE(DATE_SUBMITTED,'DD/MM/YY') END
FROM TABLE1 A
INNER JOIN TABLE2 C on A.ID = C.ID
WHERE (EARLIEST_STARTDATE IS NULL) AND
(A.WS_ELIGIBILITY_STATUS = 1) AND
(A.CLAIM_ADD_CRITERIA_FLAG = 'N' OR A.CAF = 'Y' or A.CCA_CODE = 'SC' AND A.CLAIM_ADD_CRITERIA_FLAG = 'Y') AND
(ADD_MONTHS(C.DOB, 24) BETWEEN TO_DATE('01/01/' || EXTRACT(YEAR FROM ADD_MONTHS(C.DOB, 24)),'DD/MM/YYYY') AND TO_DATE('31/03/' || EXTRACT(YEAR FROM ADD_MONTHS(C.DOB, 24)),'DD/MM/YYYY')))
答案 1 :(得分:0)
Oracle不允许您加入更新声明。您需要使用相关子查询,例如:
UPDATE TABLE1 TOP_A
SET EARLIEST_STARTDATE = (
SELECT CASE WHEN DATE_SUBMITTED <
TO_DATE('01/04/' || EXTRACT(YEAR FROM ADD_MONTHS(DOB, 24)), 'DD/MM/YYYY')
THEN TO_DATE('01/04/' || EXTRACT(YEAR FROM ADD_MONTHS(DOB, 24)),'DD/MM/YYYY')
ELSE TO_DATE(DATE_SUBMITTED,'DD/MM/YY') END
FROM TABLE1 SUB_A
INNER JOIN TABLE2 SUB_C on SUB_A.ID = SUB_C.ID
WHERE SUB_A.ID = TOP_A.ID
AND ADD_MONTHS(SUB_C.DOB, 24) BETWEEN
TO_DATE('01/01/' || EXTRACT(YEAR FROM ADD_MONTHS(SUB_C.DOB, 24)),'DD/MM/YYYY')
AND TO_DATE('31/03/' || EXTRACT(YEAR FROM ADD_MONTHS(SUB_C.DOB, 24)),'DD/MM/YYYY')
)
WHERE EARLIEST_STARTDATE IS NULL
AND WS_ELIGIBILITY_STATUS = 1
AND (CLAIM_ADD_CRITERIA_FLAG = 'N' OR CAF = 'Y' OR (CCA_CODE = 'SC' AND CLAIM_ADD_CRITERIA_FLAG = 'Y'))
/
这假定TABLE_1.ID
是唯一的。子查询执行两个表之间的连接,并且它与子查询中的WHERE SUB_A.ID = TOP_A.ID
子句正在更新的行相关联。
您的AND / OR部分有点不清楚,因此您可能需要重新考虑这些子句的括号,以获得满足您业务需求的正确布尔结果。
其他情况下的TO_DATE(DATE_SUBMITTED,'DD/MM/YY')
看起来也很可疑;如果DATE_SUBMITTED
已经是日期,那么只需直接参考,不要为此致to_date()
。在转换之前,您正在进行隐式转换为字符串;而且由于YY模型,你可能会在这个过程中失去这个世纪。
其他日期处理也可以简化。