• Oracle/PLSQL AFTER DELETE Trigger


     
    Oracle/PLSQL: AFTER DELETE Trigger
     
    An AFTER DELETE Trigger means that Oracle will fire this trigger after the DELETE operation is executed.
    译:AFTER DELETE表示在DELETE操作执行后,ORACLE会引发该触发器
    The syntax for an AFTER DELETE Trigger is:
    译:AFTER DELETE触发器的语法如下:
    CREATE or REPLACE TRIGGER trigger_name
    AFTER DELETE
        ON table_name
        [ FOR EACH ROW ]
    DECLARE
        -- variable declarations
    BEGIN
        -- trigger code
    EXCEPTION
        WHEN ...
        -- exception handling
    END;
    trigger_name is the name of the trigger to create.
    译:trigger_name表示创建的触发器名
    Restrictions:
    ·   You can not create an AFTER trigger on a view.
    ·   You can not update the :NEW values.
    ·   You can not update the :OLD values.
    译:
    限制:
    ·   不能够在视图上创建AFTER触发器。
    ·   不能够更新 :NEW 的值。
    ·   不能够更新 :OLD 的值。
    For example:
    If you had a table created as follows:
    译:如果你有一个如下的表:
    CREATE TABLE orders
    (
    order_id
    number(5),
     
    quantity
    number(4),
     
    cost_per_item
    number(6,2),
     
    total_cost
    number(8,2)
    );

    We could then create an DELETE UPDATE trigger as follows:
    译:我们像下面这样创建一个DELETE UPDATE触发器:
    CREATE OR REPLACE TRIGGER orders_after_delete
    AFTER DELETE
        ON orders
        FOR EACH ROW
    DECLARE
        v_username varchar2(10);
    BEGIN
        -- Find username of person performing the DELETE on the table
        SELECT user INTO v_username
        FROM dual;
        -- Insert record into audit table
        INSERT INTO orders_audit
         ( order_id,
           quantity,
           cost_per_item,
           total_cost,
           delete_date,
           deleted_by)
        VALUES
         ( :old.order_id,
           :old.quantity,
           :old.cost_per_item,
           :old.total_cost,
           sysdate,
           v_username );
    END;
     
     

    再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

  • 相关阅读:
    玩机分享之群晖利用反代域名访问
    Clipboard.SetText()卡住问题
    KB4040973 KB3178034 补丁导致wpf无法启动异常
    WPF 启动缓慢问题
    Jetbrains系列产品2019.2.3最新激活方法
    .net 4.0 以下HttpWebRequest Header 修改hosts方法
    Crypto++ 无法解析的外部符号 CryptoPP::AssignIntToInteger
    关于WDK开发内核签名之WHQL签名认证流程简介
    ico制作工具
    VUE监听滚动条事件
  • 原文地址:https://www.cnblogs.com/skiwdhwhssh/p/10342079.html
Copyright © 2020-2023  润新知