DB2 MERGE语句错误 [英] DB2 MERGE statement error
问题描述
我已经尝试了以下几个变体,但我继续收到错误。任何方式得到这个固定的。 DB2 10.1(DB2 for z / OS V10)
I have tried the following with a couple of variations but I continue to get errors. Any way to get this fixed. DB2 10.1 (DB2 for z/OS V10)
对于以下
MERGE INTO TRGT t
USING SRC s
ON (t.ACCTID=s.ACCTID AND s.SEQID=123)
WHEN MATCHED THEN
UPDATE SET
MyFlag = 'Y'
错误:
发现一个意外的标记SRC 。预期令牌可能包括:(。SQLSTATE = 42601
Error: An unexpected token "SRC" was found following "". Expected tokens may include: "(". SQLSTATE=42601
SQLState:42601
ErrorCode:-104
SQLState: 42601 ErrorCode: -104
然而对于以下
MERGE INTO TRGT t
USING (SELECT SEQID, ACCTID FROM SRC WHERE SEQID=123) s
ON (t.ACCTID=s.ACCTID)
WHEN MATCHED THEN
UPDATE SET
MyFlag = 'Y'
错误:
使用后面的保留字不是有效的。预期的令牌可能包括:VALUES。SQLSTATE = 42601
Error: The use of the reserved word "SELECT" following "" is not valid. Expected tokens may include: "VALUES". SQLSTATE=42601
SQLState:42601
ErrorCode:-199
SQLState: 42601 ErrorCode: -199
推荐答案
不幸(我从来不明白为什么)在DB2 for z / OS中,不能使用表作为 MERGE
,您只能使用VALUES子句。另外,如果要合并多行,则必须使用主机变量数组,并指定
Unfortunately (and I never understood why), in DB2 for z/OS, you can't use a table as a source for the MERGE
, you can only use a VALUES clause. Additionally, if you want to merge multiple rows, you have to use host variable arrays, and specify the number of values are in your array.
MERGE INTO TRGT t
USING (VALUES (:param1, :param2) FOR :paramNumRows) s
ON (t.ACCTID=s.ACCTID)
WHEN MATCHED THEN
UPDATE SET MyFlag = 'Y'
这篇关于DB2 MERGE语句错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!