简体   繁体   English

面对 DB2 中的“找不到用于 MERGE 的行”错误

[英]Facing "Row not found for MERGE" Error in DB2

I'm attempting to use a MERGE statement to update records in a physical file on an iSeries or AS400 running V7R1.我正在尝试使用 MERGE 语句来更新运行 V7R1 的 iSeries 或 AS400 上物理文件中的记录。

The issue that I am having is when attempting to use the merge on the test table, I get a Row not found for MERGE. SQLSTATE=02000我遇到的问题是,当尝试在测试表上使用合并时,我Row not found for MERGE. SQLSTATE=02000Row not found for MERGE. SQLSTATE=02000 Row not found for MERGE. SQLSTATE=02000 warning very similar to this question on SO . Row not found for MERGE. SQLSTATE=02000警告与SO上的这个问题非常相似。

The main difference in my issue is that I started by creating a copy of my test table to preserve the data, and then using the merge to update.我的问题的主要区别在于,我首先创建了测试表的副本以保留数据,然后使用合并进行更新。 The merge worked against the copy created with CPYF .合并适用于使用CPYF创建的副本。 When I was satisfied the merge was working as expected, I pointed it to the proper test file and upon execution, received the warning below.当我对合并按预期工作感到满意时,我将其指向正确的测试文件,并在执行时收到以下警告。

SQL State: 02000
Vendor Code: 100 Message: [SQL0100] Row not found for MERGE.

The target table is a membered physical file with an alias over it.目标表是一个成员物理文件,上面有一个别名。 For example, DOUG/MYDATA(F901), to create the alias I ran the following:例如,DOUG/MYDATA(F901),为了创建别名,我运行了以下命令:

CREATE ALIAS DOUG.MYDATA901 FOR DOUG.MYDATA(F901);

Query that is not updating is below:未更新的查询如下:

MERGE INTO DOUG.MYDATA901 TGT USING DOUG.TEST01 SRC
    ON TGT.PREC = SRC.PREC
WHEN MATCHED THEN
    UPDATE SET TGT.PQDS = TGT.PQDS - SRC.TTL_DIST;

However, when I make a copy of the file I'd like to update, the merge works...但是,当我复制要更新的文件时,合并工作...

CPYF FROMFILE(DOUG/MYDATA) TOFILE(DOUG/BUMYDATA) FROMMBR(F901) MBROPT(*REPLACE) CRTFILE(*YES) OUTFMT(*CHAR)

Merge code yields modified records:合并代码产生修改后的记录:

MERGE INTO DOUG.BUMYDATA TGT USING DOUG.TEST01 SRC
    ON TGT.PREC = SRC.PREC
WHEN MATCHED THEN
    UPDATE SET TGT.PQDS = TGT.PQDS - SRC.TTL_DIST;

I validated that the source and copy, when used in a select with an inner join, does in fact yield results:我验证了源和副本,当在带有内部联接的选择中使用时,确实会产生结果:

SELECT *
FROM DOUG.MYDATA901 TGT
JOIN DOUG.BUMYDATA SRC ON TGT.PREC = SRC.PREC;

Why would the MERGE work for the copied data but not the source table I created the copy from?为什么 MERGE 对复制的数据有效,但对我创建副本的源表无效?

When you're making your copy, you're only copying a single member of the file... FROMMBR(F901)当您制作副本时,您只是在复制文件的一个成员... FROMMBR(F901)

To copy all members, you'd need to use FROMMBR(*ALL) TOMBR(*FROMMBR)要复制所有成员,您需要使用FROMMBR(*ALL) TOMBR(*FROMMBR)

I'm not aware, nor could I find any documentation, of any limitation of MERGE for multi-member files.我不知道,也找不到任何文档说明MERGE对多成员文件的任何限制。 I did find the following in the v7.1 SQL Reference for ALIAS我确实在ALIASv7.1 SQL 参考中找到了以下内容

An alias that refers to an individual partition of a table or member of a database file can only be used in a select statement, CREATE INDEX, DELETE, INSERT, MERGE, SELECT INTO, SET variable, UPDATE, or VALUES INTO statement.引用表的单个分区或数据库文件成员的别名只能在选择语句、CREATE INDEX、DELETE、INSERT、MERGE、SELECT INTO、SET 变量、UPDATE 或 VALUES INTO 语句中使用。

So it seems the ALIAS should have worked, however, there are change markers in the docs around that block.所以看起来ALIAS应该有效,但是,围绕该块的文档中有更改标记。 MERGE was added at 7.1, so the change markers might be from the initial enhancement, or perhaps ALIAS support was added a bit later. MERGE是在 7.1 中添加的,因此更改标记可能来自最初的增强功能,或者可能稍后添加了ALIAS支持。

I'd recommend asking IBM, but 7.1 is out of support.我建议询问 IBM,但 7.1 不支持。

You could create a copy of your aliased file in QTEMP with data and merge your updates into that file.您可以使用数据在 QTEMP 中创建别名文件的副本,并将更新合并到该文件中。 Then use QSYS2.QCMDEXC to run a CPYF command and replace that data in your physical file member.然后使用 QSYS2.QCMDEXC 运行 CPYF 命令并替换物理文件成员中的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM