ORACLE 和 TRIGGERS(插入、更新、删除)

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

本文介绍了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),触发器主体可以使用条件谓词插入,删除和更新以检查哪个语句类型触发触发器.

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(插入、更新、删除)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ORACLE 和 TRIGGERS(插入、更新、删除)

基础教程推荐