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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)