Chinaunix首页 | 论坛 | 博客
  • 博客访问: 670612
  • 博文数量: 168
  • 博客积分: 2928
  • 博客等级: 中校
  • 技术积分: 1904
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-04 09:56
文章分类

全部博文(168)

文章存档

2010年(168)

我的朋友

分类: Oracle

2010-01-19 12:14:17

用触发器同步2个实例之间的表 收藏
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
删除数据
truncate table tagentinfo
同步数据
insert into tagentinfo select * from
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
      (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
       set name           = :NEW.name,
           agentskills    = :NEW.agentskills,
           agentworkgroup = :NEW.agentworkgroup,
           vdn            = :NEW.vdn,
           workgroupid    = :NEW.workgroupid
  elsif deleting then
    delete from where agentid = :OLD.agentid;
  end if;
exception
  when integrity_error then
    raise_application_error(errno, errmsg);
end;
/
 
 
阅读(1007) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~