如何在 PL/SQL 中增量集成数据
How to integrate data incrementally in PL/SQL
如何将来自两个不同 table 的数据增量插入另一个?
假设我有 table A 和 B,我想将行增量插入到 table C 中。行应该只插入一次(如果该行已经存在,则不应插入任何内容)和在 table C.
中不会被更新或删除
我认为它可以在循环中使用游标,如果不匹配则合并并插入数据。我完全错了,因为我收到错误消息“table 或视图不存在”。
for x in A --cursor with data from given table
loop
MERGE INTO C USING A
ON (x.id = C.id)
WHEN NOT MATCHED THEN
insert(C.id, C.email, C.address) values(x.id, x.email, x.address);
end loop;
for x in B --cursor with data from given table
loop
MERGE INTO C USING B
ON (x.id = C.id)
WHEN NOT MATCHED THEN
insert(C.id, C.email, C.address) values(x.id, x.email, x.address);
end loop;
Merge 采用 select 语句,而不是游标。您的代码某处有“光标 A 是 select...”,然后您尝试“使用 (A...) 合并到 table”,但是合并需要实际的 select。正确的格式是“merge into c using(select ...) A”并删除光标。
merge into c
using ( select id, email, address
from a
) x
on (x.id = c.id)
when not matched then
insert(c.id, c.email, c.address)
values(x.id, x.email, x.address);
merge into c
using ( select id, email, address
from b
) x
on (x.id = c.id)
when not matched then
insert(c.id, c.email, c.address)
values(x.id, x.email, x.address);
如何将来自两个不同 table 的数据增量插入另一个?
假设我有 table A 和 B,我想将行增量插入到 table C 中。行应该只插入一次(如果该行已经存在,则不应插入任何内容)和在 table C.
中不会被更新或删除我认为它可以在循环中使用游标,如果不匹配则合并并插入数据。我完全错了,因为我收到错误消息“table 或视图不存在”。
for x in A --cursor with data from given table
loop
MERGE INTO C USING A
ON (x.id = C.id)
WHEN NOT MATCHED THEN
insert(C.id, C.email, C.address) values(x.id, x.email, x.address);
end loop;
for x in B --cursor with data from given table
loop
MERGE INTO C USING B
ON (x.id = C.id)
WHEN NOT MATCHED THEN
insert(C.id, C.email, C.address) values(x.id, x.email, x.address);
end loop;
Merge 采用 select 语句,而不是游标。您的代码某处有“光标 A 是 select...”,然后您尝试“使用 (A...) 合并到 table”,但是合并需要实际的 select。正确的格式是“merge into c using(select ...) A”并删除光标。
merge into c
using ( select id, email, address
from a
) x
on (x.id = c.id)
when not matched then
insert(c.id, c.email, c.address)
values(x.id, x.email, x.address);
merge into c
using ( select id, email, address
from b
) x
on (x.id = c.id)
when not matched then
insert(c.id, c.email, c.address)
values(x.id, x.email, x.address);