合并更新oracle无法获得稳定的行集

前端之家收集整理的这篇文章主要介绍了合并更新oracle无法获得稳定的行集前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图基于另一个表(内部联接)更新Oracle中的表,但匹配的字段匹配超过1行,所以我收到一个错误

unable to get a stable set of rows

@H_403_4@
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,3) <= D.TO;

作为SELECT语句,我可以使用内部联接来提取此信息.但作为合并声明,我得到上述错误. SYSTEM是两个表中唯一匹配的数据.如何以不会错误的方式重写上述内容

我将展示这个错误的来源是什么.
考虑以下简单示例:
CREATE TABLE A_100(
  x_system int,val int
);

INSERT INTO a_100 values( 1,100 );
INSERT INTO a_100 values( 2,200 );

CREATE TABLE B_100(
  x_system int,val int
);

INSERT INTO b_100 values( 1,1100 );
INSERT INTO b_100 values( 2,2000 );
INSERT INTO b_100 values( 2,3000 );

commit;

现在请考虑这个加入:

SELECT *
FROM A_100 a
JOIN B_100 b
ON a.x_system = b.x_system AND a.x_system = 1
;

| X_SYSTEM | VAL | X_SYSTEM |  VAL |
|----------|-----|----------|------|
|        1 | 100 |        1 | 1100 |

上面的查询给出了表B_100中的一条唯一记录.如果在合并语句中使用此连接条件,则合并将运行而不会出现任何错误

MERGE INTO A_100 a
USING B_100 b
ON ( a.x_system = b.x_system AND a.x_system = 1)
WHEN MATCHED THEN UPDATE SET a.val = b.val
;

1 row merged.

现在请考虑以下加入:

SELECT *
FROM A_100 a
JOIN B_100 b
ON a.x_system = b.x_system AND a.x_system = 2
;

| X_SYSTEM | VAL | X_SYSTEM |  VAL |
|----------|-----|----------|------|
|        2 | 200 |        2 | 2000 |
|        2 | 200 |        2 | 3000 |

上述连接,来自A_100的一条记录给出了B_100的两条记录.

如果您尝试将MERGE与上述连接条件一起使用,您将获得以下内容

MERGE INTO A_100 a
USING B_100 b
ON ( a.x_system = b.x_system AND a.x_system = 2)
WHEN MATCHED THEN UPDATE SET a.val = b.val
;

Error report -
ORA-30926: unable to get a stable set of rows in the source tables

Oracle只是简单地说:

The query for one record from the left table returned two values: 2000 and 3000 from the right table. I can not assign two values from the right table to a single scalar field of the left table,this is impossible. Please change the join condition so that it gives only one unique record from the right table for each record in the left table

@H_403_4@

猜你在找的Oracle相关文章