这个触发器是用来同步更新数据的,但是没用,请教一下各位大大,到底是我写的触发器有问题,还是其他的什么原因啊create or replace trigger trigger_jsgc_qyzzxx
  after insert or update or delete  on jsgc_qyzzxx
  for each row
declare
  -- local variables here
  v_verb nvarchar2(20);
  v_src  nvarchar2(40);
  v_tablename  nvarchar2(40);
  v_colname  nvarchar2(40);
  v_err nvarchar2(500);
begin
  v_tablename := 'jsgc_qyzzxx'; 
  v_colname := 'ID';       
  if inserting then
    v_verb:='insert';
    v_src:= :NEW.ID;  
    --处理插入
    insert into jsgc_qyzzxx@orcl_qlyg
    (
        id,
        jyzbh,
        qyzy,
        zzdj
        
    )
    values
    (
        :NEW.id,
        :NEW.jyzbh,
        :NEW.qyzy,
        :NEW.zzdj
    );
  end if;
  if updating then
      v_verb:='update';
      v_src:= :OLD.id;  
      --处理修改
      update jsgc_qyzzxx@orcl_qlyg set
        jyzbh=          :NEW.jyzbh, 
        qyzy=          :NEW.qyzy,
        zzdj=          :NEW.zzdj        where
         id =         :OLD.id;
  end if;
  if deleting then
     v_verb:='delete';
     v_src:= :OLD.id; 
     -- 处理删除
     delete jsgc_qyzzxx@orcl_qlyg
     where
          id = :OLD.ID;
  end if;
exception
  when others then
    v_err := sqlerrm();
    insert into trig_syncerror (colvalue,verb,tablename,colname,errorstr) values (v_src,v_verb,v_tablename,v_colname,v_err);
end trigger_jsgc_qyzzxx;

解决方案 »

  1.   

    insert 和update两个写法不对
    直接对:new.colname赋值就好了
      

  2.   

    ..通过dblink更新别的库中的同名表?
    没这么用过
    没有用是什么意思,没有报错也没有修改?
    是不是没有commit?
      

  3.   

    修改了一下,能用了。create or replace trigger trigger_student
      after insert or update or delete  on student
      for each row
    declare
      -- local variables here
      v_verb nvarchar2(20);
      v_src  nvarchar2(40);
      v_tablename  nvarchar2(40);
      v_colname  nvarchar2(40);
      v_err nvarchar2(500);
    begin
      v_tablename := 'student';
      v_colname := 'SNO';
      if inserting then
        v_verb:='insert';
        v_src:= :NEW.SNO;
        --处理插入
        insert into student values(
        :new.sno,:new.sname,:new.ssex,:new.sage,:new.sdept,:new.birthday);
      end if;
      if updating then
          v_verb:='update';
          v_src:= :OLD.sno;
          --处理修改
          insert into student(sname,ssex,sage,sdept,birthday) values(
          :NEW.sname,:NEW.ssex,:NEW.sage,:NEW.sdept,:NEW.birthday);
      end if;
      if deleting then
        v_verb:='delete';
        v_src:= :OLD.sno;
        -- 处理删除
        delete student@orcl
        where
              sno = :OLD.sno;
      end if;
    exception
      when others then
        v_err := sqlerrm();
        insert into trig_syncerror (colvalue,verb,tablename,colname,errorstr) values (v_src,v_verb,v_tablename,v_colname,v_err);
    end trigger_student;
      

  4.   

    执行了,我的意思是没有达到预期的效果,你的目的是:当插入(更新、删除)一条记录时,往表trig_syncerror 中添加一条相应的数据,是这样的吗?
      

  5.   


    我想问问trig_syncerror 表中的errorstr字段根据啥得到的?
      

  6.   


    就把update語句改成insert??就可以了??
      

  7.   

    正常情况下,errorstr字段返回的是什么?
    我测试的时候是插入一条数据,errorstr字段是:
    ORA-04091: 表 SCOTT.STUDENT 发生了变化, 触发器/函数不能读它。这样对吗?
      

  8.   

    按照程序写的,应该是异常的时候写入trig_syncerror表中信息,怎么我这正常情况下也写入呢,是哪儿不对啊?