概述
原 用触发器同步2个实例之间的表https://blog.csdn.net/tianlesoftware/article/details/4860211版权声明: https://blog.csdn.net/tianlesoftware/article/details/4860211
1. 在2个实例之间同步表的数据
先创建DBLINK...
create database link TEST.US.ORACLE.COM
connect to TEST identified by TEST
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.6.1.36)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)';
测试Db_LINK
select * from tworkgroupnode@TEST
删除数据
truncate table tagentinfo
同步数据
insert into tagentinfo select * from tagentinfo@TEST
2. 建立触发器同步数据
建立dblink
create database link TEST2.US.ORACLE.COM
connect to ICD identified by ICD
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.6.1.36)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)';
创建触发器
create or replace trigger trib_tagentinfo
after insert or update or delete on tagentinfo
for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean;
begin
if inserting then
insert into tagentinfo@TEST2
(agentid,
name,
agentskills,
agentworkgroup,
subccno,
vdn,
workgroupid)
values
(:NEW.agentid,
:NEW.name,
:NEW.agentskills,
:NEW.agentworkgroup,
:NEW.subccno,
:NEW.vdn,
:NEW.workgroupid);
elsif updating then
update tagentinfo@TEST2
set name = :NEW.name,
agentskills = :NEW.agentskills,
agentworkgroup = :NEW.agentworkgroup,
vdn = :NEW.vdn,
workgroupid = :NEW.workgroupid
elsif deleting then
delete from tagentinfo@TEST2 where agentid = :OLD.agentid;
end if;
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
/https://img-blog.csdnimg.cn/20190217105710569.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEwNzgxNDE=,size_16,color_FFFFFF,t_70《算法导论 第三版英文版》_高清中文版.pdf
https://pan.baidu.com/s/17D1kXU6dLdU0YwHM2cvNMw
《深度学习入门:基于Python的理论与实现》_高清中文版.pdf
https://pan.baidu.com/s/1IeVs35f3gX5r6eAdiRQw4A
《深入浅出数据分析》_高清中文版.pdf
https://pan.baidu.com/s/1GV-QNbtmjZqumDkk8s7z5w
《Python编程:从入门到实践》_高清中文版.pdf
https://pan.baidu.com/s/1GUNSg4mdpeOf1LC_MjXunQ
《Python科学计算》_高清中文版.pdf
https://pan.baidu.com/s/1-hDKhK-7rDDFll_UFpKmpw
最后
以上就是雪白台灯为你收集整理的用触发器同步2个实例之间的表的全部内容,希望文章能够帮你解决用触发器同步2个实例之间的表所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复