---创建dblink,dblink_test名称,(被同步数据库的a_test)ST10766用户名,ep密码,ass100连接字符串
create public database link dblink_test
connect to aaa identified by bbb
using 'BEJING';
---删除dblink
----drop public database link dblink_test;
----建立表
create table a_test
( id int,
name varchar(20),
pass varchar(20)
)
--在远程目标数据库建立表('BEJING'指向的那个数据库)
create table b_test
( id int,
name varchar(20),
pass varchar(20)
)
select * from a_test;
insert into a_test (id,name,pass) values (1,'zzn','shanshan')
insert into b_test@dblink_test (id,name,pass) values('1','zxl','xiaolan')
----在目的数据库上,测试dblink,查询的是源数据库的表
select * from b_test@dblink_test;
select * from a_test;
----创建触发器
create or replace trigger a_b_test
after insert or update or delete
on a_test
for each row
begin
if deleting then
delete from b_test@dblink_test where id=:old.id;
end if;
if inserting then
insert into b_test@dblink_test(id,name,pass) --b_test表的字段
values(:new.id,:new.name,:new.pass); --a_test表的字段
end if;
if updating then
update b_test@dblink_test set name=:new.name,pass=:new.pass where id=:old.id;
end if;
end a_b_test;