甲骨文在触发器之前和之后的区别 [英] difference before and after trigger in oracle

查看:454
本文介绍了甲骨文在触发器之前和之后的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以举例说明oracle 10g中"before"和"after"触发器之间的区别吗?

Can somebody explain difference between "before" and "after" trigger in oracle 10g with an example ?

推荐答案

首先,我将通过定义 trigger 来开始回答: trigger 是一个存储过程,在添加,修改或删除行时运行.

First, I'll start my answer by defining trigger: a trigger is an stored procedure that is run when a row is added, modified or deleted.

触发器可以在执行操作之前 或执行后执行 AFTER .

Triggers can run BEFORE the action is taken or AFTER the action is taken.

BEFORE触发器.它们在对数据库进行任何更改之前便已运行.假设您为一家银行运行一个数据库.您有一个表accounts和一个表transactions.如果用户从其帐户中提款,则需要确保该用户在其帐户中有足够的信用额度可以进行提款.如果accounts中的余额不足,则BEFORE触发器将允许执行此操作并防止将行插入transactions中.

BEFORE triggers are usually used when validation needs to take place before accepting the change. They run before any change is made to the database. Let's say you run a database for a bank. You have a table accounts and a table transactions. If a user makes a withdrawal from his account, you would want to make sure that the user has enough credits in his account for his withdrawal. The BEFORE trigger will allow to do that and prevent the row from being inserted in transactions if the balance in accounts is not enough.

AFTER触发器.它们在对数据库进行更改(不一定已提交)之后运行.让我们回到后面的例子.成功完成事务后,您希望在accounts表中更新balance. AFTER触发器将使您能够准确地做到这一点.

AFTER triggers are usually used when information needs to be updated in a separate table due to a change. They run after changes have been made to the database (not necessarily committed). Let's go back to our back example. After a successful transaction, you would want balance to be updated in the accounts table. An AFTER trigger will allow you to do exactly that.

这篇关于甲骨文在触发器之前和之后的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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