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 row
begin
  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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM