给力--oracle数据库同步(一)

2014-11-24 11:06:43 · 作者: · 浏览: 0

数据库同步过程中常用的同步方法:
说明:
1.建立数据库之间的关联请参考上一篇《给力--oracle 与sql同步》
2.数据库同步脚本如下:
create or replace procedure prod_synchronized_data
as
--作者:chenab
--时间:2011-01-10
--功能:原XXX系统中人事与卡信息同步到XXX管理系统中
begin
-- *********************人事岗位同步 ******************* ----
--插入操作(没有的数据)
insert into _post@door
select * from _post s where not exists(
select 1 from _post@door d where d.smt_postcode=s.smt_postcode
);
--更新改变的数据
update _post@door d set
(
smt_postname,
smt_postexplain,
smt_dailycode,
smt_dailyno,
smt_shortname,
smt_enlishname,
smt_mnemonic,
smt_codeby,
smt_gbflag
)=
(select
smt_postname,
smt_postexplain,
smt_dailycode,
smt_dailyno,
smt_shortname,
smt_enlishname,
smt_mnemonic,
smt_codeby,
smt_gbflag
from _post s where s.smt_postcode=d.smt_postcode)
where exists(
select 1 from _post t where t.smt_postcode=d.smt_postcode and
not (
t.smt_postname = d.smt_postname and
t.smt_postexplain =d.smt_postexplain and
t.smt_dailycode= d.smt_dailycode and
t.smt_dailyno=d.smt_dailyno and
t.smt_shortname = d.smt_shortname and
t.smt_enlishname = d.smt_enlishname and
t.smt_mnemonic =d.smt_mnemonic and
t.smt_codeby = d.smt_codeby and
t.smt_gbflag = d.smt_gbflag
)
);
--删除操作
delete from _post@door d where not exists(
select 1 from _post s where d.smt_postcode=s.smt_postcode
);
commit;
-- *********************人事身份同步 *******************
--插入操作(没有的数据)
insert into _status@door
select * from _status s where not exists(
select 1 from _status@door d where d.smt_statuscode=s.smt_statuscode
);
--更新改变的数据
update _status@door d set
(
smt_statusname,
smt_statusexplain,
smt_foriccard,
smt_forshowcard,
smt_dailycode,
smt_dailyno,
smt_shortname,

smt_enlishname,
smt_mnemonic,
smt_codeby,
smt_gbflag)=
(select
smt_statusname,
smt_statusexplain,
smt_foriccard,
smt_forshowcard,
smt_dailycode,
smt_dailyno,
smt_shortname,
smt_enlishname,
smt_mnemonic,
smt_codeby,
smt_gbflag
from _status s where s.smt_statuscode=d.smt_statuscode)
where exists(
select 1 from _status t where t.smt_statuscode=d.smt_statuscode and
not (
t.smt_statusname=d.smt_statusname and
t.smt_statusexplain=d.smt_statusexplain and
t.smt_foriccard=d.smt_foriccard and
t.smt_forshowcard=d.smt_forshowcard and
t.smt_dailycode=d.smt_dailycode and
t.smt_dailyno=d.smt_dailyno and
t.smt_shortname=d.smt_shortname and
t.smt_enlishname=d.smt_enlishname and
t.smt_mnemonic=d.smt_mnemonic and
t.smt_codeby=d.smt_codeby and
t.smt_gbflag=d.smt_gbflag
)
);
--删除操作
delete from _status@door d where not exists(
select 1 from _status s where d.smt_statuscode=s.smt_statuscode
);
commit;
-- *********************人事行政组织同步 ******************* ----
--插入操作(没有的数据)
insert into _dept@door
select * from _dept s where not exists(select 1 from _dept@door d where d.smt_deptcode=s.smt_deptcode);
--更新改变的数据
update _dept@door d set (
smt_deptno,
smt_deptname,
smt_level,
smt_least,
smt_explain,
smt_parent_id,
smt_dailycode,
smt_dailyno,
smt_shortname,
smt_enlishname,
smt_mnemonic,
smt_codeby,
smt_gbflag,
smt_index)=
(select
smt_deptno,
smt_deptname,
smt_level,
smt_least,
smt_explain,
smt_parent_id,
smt_dailycode,
smt_dailyno,
smt_shortname,
smt_enlishname,
smt_mnemonic,
smt_codeby,
smt_gbflag,
smt_index
from _dept s where s.smt_deptcode=d.smt_deptcode)
where ex