我遇到了一个尝试使用autonomous_transaction的有趣情况.请考虑以下情况(请注意,这不是以这种方式编写的:只是概念证明):
create table t
(
id int primary key,
changed date
)
/
create or replace trigger t_trig
before insert or update
on t
for each row
declare
PRAGMA AUTONOMOUS_TRANSACTION;
begin
:new.changed := sysdate;
commit;
end;
/
insert into t(id, changed) values (1, sysdate);
insert into t(id, changed) values (2, sysdate);
截至当前时间的更改日期:
SQL> select * from t;
ID CHANGED
--------- -----------------
1 19.09.11 15:29:44
2 19.09.11 15:32:35
让我们休息5秒,然后执行以下操作:
update t set id = 2 where id = 1;
显然它会因约束违规而失败,但它也不会更改已更改的属性:
SQL> select * from t;
ID CHANGED
--------- -----------------
1 19.09.11 15:29:44
2 19.09.11 15:32:35
我的问题是:为什么会发生这种情况?我确信我误解了一些基本概念,但我无法理解.
在此先感谢您的帮助.