我有两张桌子:
A:
----------
Key | Value | PK_A
B:
-----------
Key | Value
如何在表B中的表A中插入新的(键,值),仅在表B中。我试过使用MERGE,但我不确定如何使用新的主键PK_A
MERGE INTO A
USING (SELECT key, value FROM B)
ON (A.Key = B.key AND A.value = B.value)
WHEN NOT MATCHED THEN INSERT (D.key, D.value, ???) VALUES (B.key, B.value, ???);
答案 0 :(得分:2)
创建一个序列来填充PK_A。
CREATE SEQUENCE PK_A_SEQ;
然后,
MERGE INTO A
USING (SELECT key, value FROM B)
ON (A.Key = B.key AND A.value = B.value)
WHEN NOT MATCHED THEN INSERT (D.key, D.value, D.PK_A) VALUES (B.key, B.value, PK_A_SEQ.NEXTVAL);