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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM