ORACLE和TRIGGERS(插入,更新,删除) [英] ORACLE and TRIGGERS (inserted, updated, deleted)

查看:99
本文介绍了ORACLE和TRIGGERS(插入,更新,删除)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表上使用触发器,该表每次插入,更新或删除行时都会触发.

I would like to use a trigger on a table which will be fired every time a row is inserted, updated, or deleted.

我写了这样的东西:

CREATE or REPLACE TRIGGER test001
  AFTER INSERT OR DELETE OR UPDATE ON tabletest001
  REFERENCING OLD AS old_buffer NEW AS new_buffer 
  FOR EACH ROW WHEN (new_buffer.field1 = 'HBP00') 

,并且有效. 由于如果要插入,更新或删除该行,我想做同样的事情,所以我想知道触发器中发生了什么. 我想我可以设法找到是插入行还是更新行(我可以用new_buffer检查old_buffer). 我如何知道该行是否已删除?

and it works. Since I would like to do the same things if the row is inserted, updated, or deleted, I would like to know what's happening in the trigger. I think I can manage to find if the row is inserted or updated (I can check the old_buffer with the new_buffer). How can I know if the row has been deleted?

推荐答案

来自使用触发器:

检测触发的DML操作 触发器

Detecting the DML Operation That Fired a Trigger

如果DML操作类型不止一种 可以触发一个触发器(例如,ON 插入或删除或更新 Emp_tab),则触发器主体可以使用 条件谓词INSERTING, 删除并更新以检查哪个 语句类型触发触发器.

If more than one type of DML operation can fire a trigger (for example, ON INSERT OR DELETE OR UPDATE OF Emp_tab), the trigger body can use the conditional predicates INSERTING, DELETING, and UPDATING to check which type of statement fire the trigger.

所以

IF DELETING THEN ... END IF;

应该适合您的情况.

这篇关于ORACLE和TRIGGERS(插入,更新,删除)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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