同义词同步数据
1.在源数据库创建DBLink
语法:create database like 数据库链接名 connect to 用户名
Identified by 密码 using '目标数据库的实例名';
示例:create database link DBLink_name
connect to user
dentified by password
using 'x.x.x.x:1521/orcl';
2.在源数据库创建同义词
语法:create or replace synonym 同义词名称 for
目标数据库的表名称@DBLink名称;
示例:create or replace synonym synonym_name
for table_name@DBLink_name;
3.在源数据库创建触发器
逻辑:无论源数据库中的某个表的数据是新增,修改还是删除,都通过触发器删除目标数据库中对应的那个表的那条数据,然后把源数据库中修改后的表数据通过同义词插入到目标数据库中的对应表中。
语法:
create or replace trigger 触发器名称
after insert or update or delete on 源数据库中的某张表
for each row
DECLARE
参数定义。。。
begin
IF INSERTING or UPDATING THEN
逻辑。。。
ELSIF DELETING then
逻辑。。。
ELSE
逻辑。。。
END IF;
end;