本文介绍了新旧触发码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释一下什么意思吗
can someone please explain what is meant by:
:new
和:old
.
推荐答案
:new
和:old
是伪记录,可让您访问特定列的新值和旧值.如果我有桌子
:new
and :old
are pseudo-records that let you access the new and old values of particular columns. If I have a table
CREATE TABLE foo (
foo_id NUMBER PRIMARY KEY,
bar VARCHAR2(10),
baz VARCHAR2(10)
);
然后我插入一行
INSERT INTO foo( foo_id, bar, baz )
VALUES( 1, 'Bar 1', 'Baz 1' );
然后在插入触发器之前进入行级
then in a row-level before insert trigger
:new.foo_id will be 1
:new.bar will be 'Bar 1'
:new.baz will be 'Baz 1'
同时
:old.foo_id will be NULL
:old.bar will be NULL
:old.baz will be NULL
如果您随后更新该行
UPDATE foo
SET baz = 'Baz 2'
WHERE foo_id = 1
然后在更新前行级触发器中
then in a before update row-level trigger
:new.foo_id will be 1
:new.bar will be 'Bar 1'
:new.baz will be 'Baz 2'
同时
:old.foo_id will be 1
:old.bar will be 'Bar 1'
:old.baz will be 'Baz 1'
如果我再删除该行
DELETE FROM foo
WHERE foo_id = 1
然后在before delete行级触发器中
then in a before delete row-level trigger,
:new.foo_id will be NULL
:new.bar will be NULL
:new.baz will be NULL
同时
:old.foo_id will be 1
:old.bar will be 'Bar 1'
:old.baz will be 'Baz 2'
这篇关于新旧触发码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!