首页 > 代码库 > oracle触发器加条件判断、dblink

oracle触发器加条件判断、dblink

--新增基站同步给电池组信息create or replace trigger a_b_test  after  insert or update or delete  on BJLT.BASESTATION   --REFERENCING NEW AS new_val OLD AS old_val --在这里设置名字,然后可引用新值,旧值  for each row   when(new.isnode=0)begin   if inserting then      insert into BSMS.BS_INFO@TOBSMS_BETTERY_LOCAL.REGRESS.RDBMS.DEV.US.ORACLE.COM(INFOID, INFONAME, GROUPID, ADDRESS, BUILDDATE, MAINTENANCER,            TEL, TEMPERATURE, RECTIFIERCUR,      OUTVOL, CREATETIME, SORTID, ONEOFFVOL, TWOOFFVOL, ISNODE, NODENUM, ONOFFPOWER, ONOFFPOWERMODEL,      POWERA, POWERB, POWERC, POWEROUT, POWERACUR, POWERBCUR, POWERCCUR, POWERAVOL, POWERBVOL,      POWERCVOL, DOOROPEN, HS, YANGAN, SHUIJIN, HONGWAI, KONGTIAO, VERID)    --  values (BID,BNAME,GROUPSID,      values (:new.ID,:new.NAME,:new.GROUPSID,     1,sysdate,1,      1,0,1,      1,sysdate,1,      1,1,1,      1,1,1,      -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,      1);  end if;end a_b_test;

dblink情况下,新增本地表,同步远程服务器另一张表

参考自:http://www.blogjava.net/hhhaaawwwkkk/archive/2009/05/06/269251.html

参考内容:

---创建dblink,dblink_test名称,(被同步数据库的a_test)ST10766用户名,ep密码,ass100连接字符串create public database link dblink_test   connect to ST10766 identified by ep   using ass100;---删除dblink----drop public database link dblink_test;----建立表create table a_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 (id,username,password) values(1,zxl,xiaolan)----在目的数据库上,测试dblink,查询的是源数据库的表select * from a_test@dblink_orc10; select * from a_test;----创建触发器create or replace trigger a_b_test  after  insert or update or delete  on a_test  for each rowbegin  if deleting then      delete from b_test where id=:old.id;  end if;  if inserting then      insert into b_test(id,username,password)  //b_test表的字段      values(:new.id,:new.name,:new.pass); //a_test表的字段  end if;  if updating then     update b_test set username=:new.name,password=:new.pass where id=:old.id;  end if;end a_b_test;

 

oracle触发器加条件判断、dblink