比如说,现在一张表testTab,有三个属性,name,pwd,type.如果某一条记录的name或者pwd任意一个值更新了,就触发,把更新前的记录插入到testTab_bak中,但这条记录的type更新就不触发。这个触发器哪位高手能写出来?不胜感激

解决方案 »

  1.   

    触发器监视行级触发,触发的时候去判断更新了哪几个字段(比较字段的.NEW和.OLD的值),决定是否写入新表中
      

  2.   

    SQL> create table dept_bak as select * from dept where 1=2;表已创建。SQL> create or replace trigger test
      2    after update of deptno,dname on dept
      3    for each row
      4  declare
      5    -- local variables here
      6  begin
      7     insert into dept_bak values (:old.deptno,:old.dname,:old.loc);
      8  end test;
      9  /触发器已创建SQL> show error
    没有错误。
    SQL> select * from dept_bak;未选定行
    SQL> update dept set deptno=50 where deptno=40;已更新 1 行。SQL> commit;提交完成。SQL> select * from dept_bak;    DEPTNO DNAME          LOC
    ---------- -------------- -------------
            40 OPERATIONS     BOSTON
    SQL> update dept set dname='ACMILAN' where deptno=50;已更新 1 行。SQL> commit;提交完成。SQL> select * from dept_bak;    DEPTNO DNAME          LOC
    ---------- -------------- -------------
            40 OPERATIONS     BOSTON
            50 OPERATIONS     BOSTON
    SQL> update dept set loc='beijing' where deptno=50;已更新 1 行。SQL> commit;提交完成。SQL> select * from dept_bak;    DEPTNO DNAME          LOC
    ---------- -------------- -------------
            40 OPERATIONS     BOSTON
            50 OPERATIONS     BOSTONSQL>
      

  3.   

    create or replace trigger test
     after update of deptno,dname on dept
     for each row
     declare
     -- local variables here
     begin
     insert into dept_bak values (:old.deptno,:old.dname,:old.loc);
     end test;