• 触发器after和before


    --after和before
    CREATE OR REPLACE TRIGGER del_emp1
                   BEFORE update OR insert OR delete ON scott.emp
             REFERENCING new AS nn  old AS oo
             FOR EACH ROW
             WHEN (nn.sal > 2000)
    BEGIN
             IF INSERTING THEN
                dbms_output.put_line('THE OPERATION IS INSERT');
             ELSIF UPDATING THEN
                 dbms_output.put_line('THE OPERATION IS UPDATE');
             ELSIF DELETING THEN
                 dbms_output.put_line('THE OPERATION IS DELETE');
             ELSE
                 dbms_output.put_line('OTHERS OPERATION');
             END IF;
    END;
    CREATE OR REPLACE TRIGGER del_emp2
                   after update OR insert OR delete ON scott.emp
             REFERENCING new AS nn  old AS oo
             FOR EACH ROW
             WHEN (nn.sal > 2000)
    BEGIN
             IF INSERTING THEN
                dbms_output.put_line('THE OPERATION IS INSERT');
             ELSIF UPDATING THEN
                 dbms_output.put_line('THE OPERATION IS UPDATE');
             ELSIF DELETING THEN
                 dbms_output.put_line('THE OPERATION IS DELETE');
             ELSE
                 dbms_output.put_line('OTHERS OPERATION');
             END IF;
    END;
    update emp set sal=7000 where emp.ename='SMITH';
    --after和before的区别是:before是先执行begin后触发触发器,after是先执行触发器而后执行begin内容.
    CREATE OR REPLACE TRIGGER check_emp
                   BEFORE update OR insert OR delete ON scott.emp
             REFERENCING new AS nn old AS oo
             FOR EACH ROW
             /*WHEN (nn.sal < 2000)*/
    BEGIN
             IF INSERTING THEN
                dbms_output.put_line('THE OPERATION IS INSERT');
             ELSIF UPDATING THEN
                 dbms_output.put_line('THE OPERATION IS UPDATE');
             ELSIF DELETING THEN
                 dbms_output.put_line('THE OPERATION IS DELETE');
             ELSE
                 dbms_output.put_line('OTHERS OPERATION');
             END IF;
    END;
    select * from emp;
    begin  
           savepoint s1;
           delete emp where sal=4000;
           rollback to s1;
    end;
    
           
  • 相关阅读:
    合并两个有序链表
    有效括号方法二
    有效括号
    es6 中的模块化
    XMLHttpRequest 对象
    AST
    php读写文件方式
    vue开发中遇到的问题
    sublime操作
    cmd命令
  • 原文地址:https://www.cnblogs.com/kiskistian/p/7268576.html
Copyright © 2020-2023  润新知