AFTER DELETE Trigger

本文介绍了Oracle中AFTERDELETE触发器的概念与用法,包括其语法结构及限制条件,并通过一个具体的订单表删除触发器示例说明如何实现数据审计。
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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值