[英]Merge statement not matched with the ON Clause in oracle sql
I have oracle sql merge statement query in which i want to merge the data from PROCESS_MONITOR_STATISTIC
to TEMP_PROCESS_MONITOR_STATISTIC
table. 我有oracle sql合并语句查询,我想在其中将数据从
PROCESS_MONITOR_STATISTIC
合并到TEMP_PROCESS_MONITOR_STATISTIC
表。
The ID are sequence generated in PROCESS_MONITOR_STATISTIC
table. 该ID是在
PROCESS_MONITOR_STATISTIC
表中生成的序列。 So i always want to get the data into TEMP_PROCESS_MONITOR_STATISTIC
table with the ID greater than the ID from PROCESS_MONITOR_STATISTIC
. 所以我一直想将数据放入
TEMP_PROCESS_MONITOR_STATISTIC
表中,其ID大于来自PROCESS_MONITOR_STATISTIC
。 So that i will always want to insert the latest data into the TEMP_PROCESS_MONITOR_STATISTIC
table when i execute the query. 因此,当我执行查询时,我总是想将最新数据插入
TEMP_PROCESS_MONITOR_STATISTIC
表中。 I tried this query but not resulting the latest data. 我尝试了此查询,但未得到最新数据。
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);
If all you're doing is "inserting items into table B from A, which don't already exist". 如果您要做的只是“将项目从A插入表B,但尚不存在”。
This should do it: 应该这样做:
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;
No MERGE needed. 无需合并。
As another option ... you could try this: 作为另一种选择...您可以尝试以下操作:
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 );
Restricting it solely based on your largest ID from the target table. 仅根据目标表中的最大ID对其进行限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.