用dblink+job做两个库中表T的单向同步
源库中表T有一列为insert_time,记录入库时间,值为sysdate,目标库中建一张临时表tmp(id,insert_time);
每次做完同步后会把临时表中insert_time更新为从源库中读取数据中insert_time的最大值,下次同步时就从源库的表T中去读比这个最大值大的那些数据1但这个情况我有没有可能会丢数据,那个时间点的数据没有读全,因为下次更新时就不会插入那个时间的数据
2或者我把那个时间点往前推一秒,这样也有问题,如果源表那边数据没有更新的话,我目标库这边就永远读不到那个时间点的数据了请问我该如何解决这个问题
源库中表T有一列为insert_time,记录入库时间,值为sysdate,目标库中建一张临时表tmp(id,insert_time);
每次做完同步后会把临时表中insert_time更新为从源库中读取数据中insert_time的最大值,下次同步时就从源库的表T中去读比这个最大值大的那些数据1但这个情况我有没有可能会丢数据,那个时间点的数据没有读全,因为下次更新时就不会插入那个时间的数据
2或者我把那个时间点往前推一秒,这样也有问题,如果源表那边数据没有更新的话,我目标库这边就永远读不到那个时间点的数据了请问我该如何解决这个问题
有就可以用merge intomerge into a
using (select id,name from b ) c
on(a.id=c.id )
when matched then update set a.name=c.name
when not matched then insert (a.id,a.name) values (c.id,c.name);
作用:利用表 b 更新表a ,条件是a.id=b.id,如果a表中没有该条件的数据就插入。如果你的数据量很大,此sql效率非常高。
create table a(id number(1),name varchar2(10));
create table b(id number(1),name varchar2(10));
insert into a values(1,'2');
insert into b values(1,'1');
insert into b values(2,'2');merge into a
using (select id,name from b ) c
on(a.id=c.id )
when not matched then insert (a.id,a.name) values (c.id,c.name);
2 using (select id,name from b ) c
3 on(a.id=c.id )
4 when not matched then insert (a.id,a.name) values (c.id,c.name);1 行已合并。SQL> merge into a
2 using (select id,name from b ) c
3 on(a.id=c.id )
4 when matched then update set a.name=c.name;2 行已合并。