当涉及两个以上的表时,更新SQL for Oracle-ORA-00933

时间:2018-08-07 19:56:45

标签: sql oracle oracle11g

我对编写SQL比较陌生。我写了以下内容:

UPDATE PS_EMAIL_ADDRESSES C
SET C.EMAIL_ADDR = B.SFA_CR_EMAIL_ADDR
 FROM PS_LOAN_ORIGNATN A, PS_SFA_COD_BORROWR B
 WHERE A.EMPLID <> A.BORR_EMPLID
    AND A.AID_YEAR = '2019'
    AND A.ACAD_CAREER = 'UGRD'
    AND A.BORR_EMPLID <> ' '
    AND B.SFA_CR_AWARD_YEAR = A.AID_YEAR
    AND B.SFA_CR_ID_SSN = A.BORR_SSN
    AND B.SFA_CR_EMAIL_ADDR <> ' '
    AND B.SFA_CR_DOCUMENT_ID = (SELECT MAX( D.SFA_CR_DOCUMENT_ID)
 FROM PS_SFA_COD_BORROWR D
 WHERE D.SFA_CR_AWARD_YEAR = B.SFA_CR_AWARD_YEAR
    AND D.SFA_CR_ID_SSN = B.SFA_CR_ID_SSN
    AND D.SFA_CR_EMAIL_ADDR <> ' ')
    AND EXISTS (SELECT 1
 FROM PS_EMAIL_ADDRESSES C
 WHERE C.EMPLID = A.BORR_EMPLID
    AND C.E_ADDR_TYPE = 'PEM'
    AND C.EMAIL_ADDR <> B.SFA_CR_EMAIL_ADDR)

但是在SQL Fiddle上检查它,我得到了ORA-00933。我可能要求的不正确,但是我一直在研究不同的版本。

1 个答案:

答案 0 :(得分:0)

一些问题:这不是Oracle Sql语法,您已经重用了别名C,并且缩进有点难以遵循。

看看这是否对您有用:

UPDATE PS_EMAIL_ADDRESSES E
   SET E.EMAIL_ADDR = (SELECT B.SFA_CR_EMAIL_ADDR
  FROM PS_LOAN_ORIGNATN A, PS_SFA_COD_BORROWR B
 WHERE A.EMPLID <> A.BORR_EMPLID
   AND A.AID_YEAR = '2019'
   AND A.ACAD_CAREER = 'UGRD'
   AND A.BORR_EMPLID <> ' '
   AND B.SFA_CR_AWARD_YEAR = A.AID_YEAR
   AND B.SFA_CR_ID_SSN = A.BORR_SSN
   AND B.SFA_CR_EMAIL_ADDR <> ' '
   AND B.SFA_CR_DOCUMENT_ID = (SELECT MAX( D.SFA_CR_DOCUMENT_ID)
                                 FROM PS_SFA_COD_BORROWR D
                                WHERE D.SFA_CR_AWARD_YEAR = B.SFA_CR_AWARD_YEAR
                                  AND D.SFA_CR_ID_SSN = B.SFA_CR_ID_SSN
                                  AND D.SFA_CR_EMAIL_ADDR <> ' ')
   AND EXISTS (SELECT 1
                 FROM PS_EMAIL_ADDRESSES C
                WHERE C.EMPLID = A.BORR_EMPLID
                  AND C.E_ADDR_TYPE = 'PEM'
                  AND C.EMAIL_ADDR <> B.SFA_CR_EMAIL_ADDR)
);