我将展示这个错误的来源是什么.
考虑以下简单示例:
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