更新内部加入Toad

时间:2017-12-05 17:14:23

标签: sql oracle join sql-update

请注意,这不是一个重复的问题。

我有一个声明,我需要在Toad中运行。我知道如何将其编写为内部联接更新语句,但Toad不允许在UPDATE语句中进行内部联接。如果我把它写成SELECT语句,它就可以了。但是当我将其重写为UPDATE语句时,Toad将不会接受它。我怎么写这个,所以Toad会接受吗?

UPDATE C INNER JOIN D
ON C.SYSTEM = D.SYSTEM
SET C.REF_CD = D.CODE,
    C.REF_DT = TO_DATE('12/05/2017', 'MM/DD/YYYY')
WHERE C.CODE = '123'
AND D.CODE IS NOT NULL
AND C.CLOSED = 'N'
AND C.RCVD_DT >= TO_DATE('12/01/2017', 'MM/DD/YYYY')
AND C.RCVD_DT <= TO_DATE('12/04/2017', 'MM/DD/YYYY')
AND SUBSTR(C.SSN,7,3) >= D.FROM
AND SUBSTR(C.SSN,7,3) <= D.TO;

我现在也尝试将其写为Merge语句(Toad允许):

MERGE INTO C
USING D
ON (C.SYSTEM = D.SYSTEM)
WHEN MATCHED THEN
UPDATE SET C.REF_CD = D.CODE,
           C.REF_DT = TO_DATE('12/05/2017', 'MM/DD/YYYY')
   WHERE C.CODE = '123'
   AND D.CODE IS NOT NULL
   AND C.CLOSED = 'N'
   AND C.RCVD_DT >= TO_DATE('12/01/2017', 'MM/DD/YYYY')
   AND C.RCVD_DT <= TO_DATE('12/04/2017', 'MM/DD/YYYY')
   AND SUBSTR(C.SSN,7,3) >= D.FROM
   AND SUBSTR(C.SSN,7,3) <= D.TO;

这给了我一个新的错误,因为系统匹配多行。但是,它是我可以加入的唯一匹配字段。

0 个答案:

没有答案