ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用触发器同步2个实例之间的表

用触发器同步2个实例之间的表

原创 Linux操作系统 作者:jasoname 时间:2011-01-19 16:38:13 0 删除 编辑

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;
/

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22741583/viewspace-684239/,如需转载,请注明出处,否则将追究法律责任。

上一篇: RMAN恢复
下一篇: ASM安装
请登录后发表评论 登录
全部评论

注册时间:2010-01-22

  • 博文量
    146
  • 访问量
    236070