我的触发器create or replace trigger document_trigger
    before INSERT or delete or update  ON DOCUMENT
    FOR EACH ROW
    
BEGIN
       IF INSERTING THEN 
         INSERT INTO syncres (syncresid,RESTYPE,REFERRESOURCEID) values (EXAMCERT_SEQ.NEXTVAL,:new.resourcetypeid,:new.docid);
      ELSIF DELETING THEN
        DELETE FROM syncres s WHERE s.referresourceid=:OLD.docid and s.restype = :old.resourcetypeid;
      END IF;
    END;
DOCUMENT(docid,resourcetypeid)  是一张表,现在我要做的是 此表新插入一条数据的同时,也向synres(id,docidresourcetypeid,)插入这条数据
但是,问题出现在 
insert into document(1,345)  后 synres 有两条 这个数据。结果如(1,1,345) (2,1,345)
高手帮忙

解决方案 »

  1.   

    documnet里面是不是也有两条数据?
      

  2.   

    CREATE  or replace trigger document_trigger
        before INSERT or delete or update  ON DOCUMENT
        FOR EACH ROW
    BEGIN
           IF INSERTING THEN 
             INSERT INTO syncres(syncresid,RESTYPE,REFERRESOURCEID) values(ABCD_SEQ.NEXTVAL,:new.resourcetypeid,:new.docid);
          ELSIF DELETING THEN
            DELETE FROM syncres s WHERE s.referresourceid=:OLD.docid and s.restype = :old.resourcetypeid;
          END IF;
          --COMMIT;--触发器中不能够有commit
    END document_trigger;
    经过测试没有问题。
      

  3.   

    这个现象,我记得以前在TOM的哪本书或文章上见过,只有特殊情况才会出现
      

  4.   

    谁能翻墙? 把下面的几个链接贴出来Now, before we discuss this - you must be made aware that not only do we NOT promise to fire the trigger once - we actually promise to fire it more than once in certain cases: http://tkyte.blogspot.com/2005/08/something-different-part-i-of-iii.htmlhttp://tkyte.blogspot.com/2005/08/part-ii-seeing-restart.htmlhttp://tkyte.blogspot.com/2005/09/part-iii-why-is-restart-important-to.html
    this has *always* been true - complex logic in triggers is a scary scary thing (I don't are what database you are using - it is scary).