如果我现在有两个表(table1,table2)定义完全相同。
我要现实如果table1表改变,另一个table2表也跟着改
就比如表table1(a,b,c) 其中a,b是主键。CREATE OR REPACLE TRIGGER tr
AFTER UPDATE D,E,F OR DELETE
ON TABLE_NAME 
FOR EACH ROW
WHEN (table1.a)我不知道怎么写啊。。我看到书上的例子没有我这样啊。。
请教高手。。谢谢。。

解决方案 »

  1.   

    举个例子create or replace trigger trgRollbackDeviceTransfer
      after update on asset_transfer_interface  
      for each row
    declare
      v_orig_dept varchar2(20);
      v_from_table varchar2(50);
    begin
      if UPDATING('process_status') then
         if :NEW.process_status = 'REJECT' then
            --本次转移被拒绝
            v_from_table := UPPER(trim(:NEW.description));
            if v_from_table='LBS_DEPT_INFO' then
               v_orig_dept := 'LBS_'||:NEW.dept_no_from;
            elsif v_from_table='GBS_DEPT_INFO' then
               v_orig_dept := 'GBS_'||:NEW.dept_no_from;
            else
               v_orig_dept := :NEW.dept_no_from;   
            end if;
            update devicebasicinfo set depid = v_orig_dept
            where deviceid = :NEW.deviceid;
         elsif :NEW.process_status = 'UPLOAD' then
            null;
         else      
             --本次转移完成
            update device_interface_log set process_flag='1'
            where deviceid=:NEW.deviceid and process_type='T' 
            and interface_id = :NEW.transfer_interface_id;     
         end if;     
      end if;
    end;
    /
      

  2.   

    谢谢。。tgm78() ,我学习学习。。我主要是应用在分布式数据库中
    由于直接B写成A的视图的话,执行pl/sql的时候特别慢,所以我正在想办法。。
    呵呵。。
      

  3.   

    那也不至于更新两个表啊。更浪费资源.而且,trigger这东西不保险。根据现实情况,建立同义词,快照等等都可以。
      

  4.   

    你只是想通过b数据库访问a数据库中的表的话,
    建dblink,直接选就可以了
    select xxx from xxx@dblink;
      

  5.   

    我觉得楼主完全没有 必要这样做的
    你可以把B表建成一个试图
    create view view_b as 
    select * from a就可以了 那B中的数据就会和A一样,而且完全不需要什么TRIGGER