DB2 - SQL - MERGE - 一个意外的标记 -

DB2 - SQL - MERGE - An unexpected token -

我是这里的初学者,对错误深表歉意:-(

我尝试执行 Marge,但不幸的是一直出现同样的错误,我不知道自己做错了什么。

MERGE INTO TB_CLIENT_ACCOUNT_LINK as A

    USING

        (SELECT client_id, account_id, PROPER_NAME
           FROM TB_CLIENT_ACCOUNT_LINK
          WHERE client_id=233176) as B

        ON (A.account_id = B.account_id)

        WHEN MATCHED THEN

        UPDATE
           SET A.PROPER_NAME = B.PROPER_NAME
         WHERE A.client_id=110966
           AND A.PROPER_NAME IS NOT NULL

我有错误:

An unexpected token "where" was found following "NAME = B.PROPER_NAME". Expected tokens may include: "OVERLAPS".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.72.52 SQL Code: -104, SQL State: 42601

我想做什么?

我想将 PROPER_NAME 从一个客户端复制到另一个具有相同 ACCOUNT_ID 的客户端。

我不想这样做,我想使用 marge 或(如果可能的话)高级更新选项。

我一般都是这样

update TB_CLIENT_ACCOUNT_LINK set PROPER_NAME = 'NAME1'
 where A.client_id=110966 and A.PROPER_NAME is not null;
update TB_CLIENT_ACCOUNT_LINK set PROPER_NAME = 'NAME2'
 where A.client_id=110966 and A.PROPER_NAME is not null;
update TB_CLIENT_ACCOUNT_LINK set PROPER_NAME = 'NAME3'
 where A.client_id=110966 and A.PROPER_NAME is not null;

等等

参考MERGE statement语法。
你的陈述有很多错误。

  • 无法在 update-operation
  • 中指定 WHERE 子句
  • assignment-clause 左侧不能包含相关名称

改用以下方法之一。

MERGE INTO TB_CLIENT_ACCOUNT_LINK as A
USING
(select client_id,account_id,PROPER_NAME from TB_CLIENT_ACCOUNT_LINK where client_id=233176) as B
ON (A.account_id = B.account_id)
--AND A.client_id=110966 and A.PROPER_NAME is not null
when matched
-- Comment out the following line, if you uncommented the one above
AND A.client_id=110966 and A.PROPER_NAME is not null
then update set PROPER_NAME = B.PROPER_NAME