توضیحات
AFTER DELETE Trigger به معنی این است که بعد از اجرای یک دستور delete، یک تریگر فعال (fire) شود.دستور
دستور Ater delete triger به صورت زیر نوشته میشود:|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 |
CREATE [ OR REPLACE ] TRIGGER trigger_nameAFTER DELETE ON table_name [ FOR EACH ROW ]DECLARE -- variable declarationsBEGIN -- trigger codeEXCEPTION WHEN ... -- exception handlingEND; |
مثال
مثالی از دستور ساخت After Delete triger را مشاهده میکنیم:|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 |
CREATE TABLE orders( order_id number(5), quantity number(4), cost_per_item number(6,2), total_cost number(8,2));CREATE OR REPLACE TRIGGER orders_after_deleteAFTER DELETE ON orders FOR EACH ROWDECLARE 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; |