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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| set echo on
drop table journal
drop table journal succeeded.
drop table t1 cascade constraints
drop table t1 succeeded.
drop table t2
drop table t2 succeeded.
create table journal (trig varchar2(30), val number)
create table succeeded.
create table t1 (a number primary key)
create table succeeded.
create table t2 (a number references t1(a) on delete cascade)
create table succeeded.
insert into t1 values (1)
1 rows inserted
insert into t1 values (2)
1 rows inserted
insert into t2 values (1)
1 rows inserted
insert into t2 values (1)
1 rows inserted
create trigger trig1
after delete
on t1
begin
insert into journal values('trig1', null);
end;
trigger trig1 Compiled.
create trigger trig2
after delete
on t2
begin
insert into journal values('trig2', null);
end;
trigger trig2 Compiled.
create trigger trig3
after delete
on t2
for each row
begin
insert into journal values('trig3', :old.a);
end;
trigger trig3 Compiled.
delete t1 where a = 10
0 rows deleted
select * from journal
TRIG VAL
------------------------------ ----------------------
trig2
trig1
2 rows selected
rollback
rollback succeeded.
delete t1 where a = 2
1 rows deleted
select * from journal
TRIG VAL
------------------------------ ----------------------
trig2
trig1
2 rows selected
rollback
rollback succeeded.
delete t1 where a = 1
1 rows deleted
select * from journal
TRIG VAL
------------------------------ ----------------------
trig3 1
trig3 1
trig2
trig1
4 rows selected |
Partager