新旧触发代码 [英] new and old trigger code

查看:24
本文介绍了新旧触发代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下是什么意思:

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

然后在删除行级触发器之前,

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'

这篇关于新旧触发代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆