DML触发器BEFORE和AFTER对插入、更新和删除是怎样设置允许操作和禁止操作的呢?
请前辈们来个简单的例子!谢谢!

解决方案 »

  1.   


    create or replace trigger tri_prent
      before  INSERT or update or delete  ON yxgl_kcgl
      FOR EACH ROWdeclare
    begin
       if  :new.szdw not in  ('500171','500172','500173','500174','500175','500176','500177','500178','500179','500180','500181','300005') then          raise_application_error(-20000,'不能操作数据!');   end if;
    end tri_prent;
      

  2.   

    CREATE OR REPLACE TRIGGER JXXLUSER.MYTRIGGER  ----触发器名
    AFTER INSERT  ----插入后触发
    ON JXXLUSER.JOBTEST -----在此表上触发
    FOR EACH ROW
    DECLARE
    BEGIN
       INSERT INTO TEST1 VALUES(4,5); ----
       EXCEPTION
         WHEN OTHERS THEN
           -- Consider logging the error and then re-raise
           RAISE;
    END ;
      

  3.   

    我才第一次发帖,结贴率就为0真无语!
    要是插入、更新和删除都将会是没问题的,用BEFORE和AFTER来禁止操作
    只能用抛出异常吗???
      

  4.   

    create or replace trigger tri_super_user 
    before insert,delete
    on users
    for each row
    as 
    declare 
     v_user varchar2(30):=new.username;
     begin 
      if v_user='superuser' then 
         raise_application_error(-18752,'superuser couldnot allow insert new or delete it');
       return;
      end if;
    end tri_super_user;
    /