合并语句与 Oracle 中的 ON 子句不匹配 sql
Merge statement not matched with the ON Clause in oracle sql
我有 oracle sql 合并语句查询,我想在其中将数据从 PROCESS_MONITOR_STATISTIC
合并到 TEMP_PROCESS_MONITOR_STATISTIC
table.
ID 是在 PROCESS_MONITOR_STATISTIC
table 中生成的序列。所以我总是想将数据放入 TEMP_PROCESS_MONITOR_STATISTIC
table 中,ID 大于 PROCESS_MONITOR_STATISTIC
中的 ID。所以我总是想在执行查询时将最新数据插入 TEMP_PROCESS_MONITOR_STATISTIC
table 中。我试过这个查询,但没有得到最新的数据。
merge into TEMP_PROCESS_MONITOR_STATISTIC TSM
using (
select * from
(select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE from
PROCESS_MONITOR_STATISTIC@FONIC_RETAIL) where rownum<=1000
) data
ON (TSM.ID > data.ID)
when not matched then
insert(ID,PROCESS_MONITOR_ID,PROCESS_START_DATE)
values(data.ID,data.PROCESS_MONITOR_ID,data.PROCESS_START_DATE);
如果您所做的只是"inserting items into table B from A, which don't already exist"。
应该这样做:
INSERT INTO TEMP_PROCESS_MONITOR_STATISTIC
select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE
from PROCESS_MONITOR_STATISTIC@FONIC_RETAIL
minus
select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE
from TEMP_PROCESS_MONITOR_STATISTIC;
不需要合并。
作为另一种选择......你可以试试这个:
INSERT INTO TEMP_PROCESS_MONITOR_STATISTIC
select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE
from PROCESS_MONITOR_STATISTIC@FONIC_RETAIL
where id > (select max(id) from TEMP_PROCESS_MONITOR_STATISTIC );
仅根据目标 table 的最大 ID 对其进行限制。
我有 oracle sql 合并语句查询,我想在其中将数据从 PROCESS_MONITOR_STATISTIC
合并到 TEMP_PROCESS_MONITOR_STATISTIC
table.
ID 是在 PROCESS_MONITOR_STATISTIC
table 中生成的序列。所以我总是想将数据放入 TEMP_PROCESS_MONITOR_STATISTIC
table 中,ID 大于 PROCESS_MONITOR_STATISTIC
中的 ID。所以我总是想在执行查询时将最新数据插入 TEMP_PROCESS_MONITOR_STATISTIC
table 中。我试过这个查询,但没有得到最新的数据。
merge into TEMP_PROCESS_MONITOR_STATISTIC TSM
using (
select * from
(select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE from
PROCESS_MONITOR_STATISTIC@FONIC_RETAIL) where rownum<=1000
) data
ON (TSM.ID > data.ID)
when not matched then
insert(ID,PROCESS_MONITOR_ID,PROCESS_START_DATE)
values(data.ID,data.PROCESS_MONITOR_ID,data.PROCESS_START_DATE);
如果您所做的只是"inserting items into table B from A, which don't already exist"。
应该这样做:
INSERT INTO TEMP_PROCESS_MONITOR_STATISTIC
select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE
from PROCESS_MONITOR_STATISTIC@FONIC_RETAIL
minus
select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE
from TEMP_PROCESS_MONITOR_STATISTIC;
不需要合并。
作为另一种选择......你可以试试这个:
INSERT INTO TEMP_PROCESS_MONITOR_STATISTIC
select ID,PROCESS_MONITOR_ID,PROCESS_START_DATE
from PROCESS_MONITOR_STATISTIC@FONIC_RETAIL
where id > (select max(id) from TEMP_PROCESS_MONITOR_STATISTIC );
仅根据目标 table 的最大 ID 对其进行限制。