See also: Why And When To Use Pre-Update and Pre-Insert Triggers In Oracle Forms

Pre-Update Fires during the Post and CommitTransactions process, before a row is updated in Oracle Forms. It fires once for each record that is marked for update.

The following example writes a row into an Audit Table showing old discount and new discount for a
given customer, including timestamp and username making the change.

DECLARE
old_discount NUMBER;
new_discount NUMBER := :Customer.Discount_Pct;
oper_desc VARCHAR2(80);
CURSOR old_value IS SELECT discount_pct FROM customer
WHERE CustId = :Customer.CustId;
BEGIN
/*
Fetch the old value of discount percentage from the database by CustomerId. We need to do this since the  value of :Customer.Discount_Pct will be the new value we’re getting ready to commit and we want to record for posterity the old and new values. We could use SELECT...INTO but choose an explicit cursor for efficiency.
*/
OPEN old_value;
FETCH old_value INTO old_discount;
CLOSE old_value;
/*  If the old and current values are different, then we need to write out an audit record */
IF old_discount <> new_discount THEN
/* Construct a string that shows the operation of Changing the old value to the new value. e.g.’Changed Discount from 13.5% to 20%’
*/
oper_desc := ’Changed Discount from ’||
TO_CHAR(old_discount)||’% to ’||
TO_CHAR(new_discount)||’%’;
/*
Insert the audit record with timestamp and user
*/
INSERT INTO cust_audit( custid, operation, username, timestamp )
VALUES ( :Customer.CustId,oper_desc,USER,SYSDATE );
END IF;
END;

Pre-Insert trigger

Pre-Insert Fires during the Post and Commit Transactions process, before a row is inserted. It fires once for each record that is marked for insert.
 
Example
This example assigns a primary key field based on a sequence number, and then writes a row into an
auditing table, flagging creation of a new order.
DECLARE
CURSOR next_ord IS SELECT orderid_seq.NEXTVAL FROM dual;
BEGIN
/* Fetch the next sequence number from the explicit cursor directly into the item in the Order record. Could use SELECT...INTO, but explicit cursor is more efficient. */
OPEN next_ord;
FETCH next_ord INTO :Order.OrderId;
CLOSE next_ord;
/*
Make sure we populated a new order id ok...
*/
IF :Order.OrderId IS NULL THEN
Message(’Error Generating Next Order Id’);
RAISE Form_trigger_Failure;
END IF;
/*
Insert a row into the audit table
*/
INSERT INTO ord_audit( orderid, operation, username, timestamp)
VALUES ( :Order.OrderId,’New Order’,USER, SYSDATE );
END;
Follow to get notifications for more tutorials with source code, thanks.
 


Pre-insert and Pre-update in Oracle Forms

Reviewed by Rasa on

Mar 24

Rating: 
5

Pre-Update and Pre-Insert Trigger Examples For Oracle Forms的更多相关文章

  1. Map Columns From Different Tables and Create Insert and Update Statements in Oracle Forms

    This is one of my most needed tool to create Insert and Update statements using select or alias from ...

  2. Trigger Execution Sequence Of Oracle Forms

    Sequence of triggers fires on Commit.1.  KEY Commit2.  Pre Commit3.  Pre/On/Post Delete4.  Pre/On/Po ...

  3. An Example of On-Error Trigger in Oracle Forms

    I wrote this trigger around 4 years ago to handle errors in an application based on Oracle Forms 6i. ...

  4. Pre-Query trigger in Oracle D2k / Oracle Forms

    Pre-Query trigger in Oracle D2k / Oracle Forms DescriptionFires during Execute Query or Count Query ...

  5. Trigger Execution Sequence in Oracle Forms

    Introduction ------------ This document lists the order in which triggers fire in Oracle Forms 4.5: ...

  6. 8 Most Required Examples Reference For Oracle Forms

    Check the following 8 Links for best Oracle Forms examples with source code (Fmb files), which will ...

  7. Learn How To Create Trigger In Oracle Forms

    I have written many posts related to triggers in Oracle Forms, I have given examples for Form Level ...

  8. Writing On-Error Trigger In Oracle Forms

    Suppose you want to handle an error in oracle forms and want to display custom error message for tha ...

  9. Using Post-Form Trigger In Oracle Forms

    Post-Form trigger in Oracle Forms fires during the Leave the Form process, when a form is exited.   ...

随机推荐

  1. 深入了解webservice_概念总结

    最近公司需要对java web端的第三方接口进行测试,使用WebService+TestNG实现,TsetNg是常用的自动化测试框架,这就不介绍了. WebService是一种跨编程语言和跨操作系统平 ...

  2. Java throw:异常的抛出怎么回事

    到目前为止,你只是获取了被Java运行时系统抛出的异常.然而,程序可以用throw语句抛出明确的异常.Throw语句的通常形式如下:    throw ThrowableInstance;这里,Thr ...

  3. 利用VHD虚拟文件加密自己的个人信息

    1.制作VHD磁盘 计算机—管理—磁盘管理—操作—创建VHD 2.挂载卸载VHD磁盘 磁盘管理—操作—附加VHD 选择只读则不允许修改文件内容 3.用途 这样一个虚拟磁盘就被建立出来.它实际上仅仅是一 ...

  4. 【PHP设计模式 11_QiaoJie.php】桥接模式(针对 二维模型)

    <?php /** * [桥接模式(针对 二维模型)] * 对于多维度需要处理的事情,多耦合 * 第一维度,发送信息的类型:站内信.email.手机短信 * 第二维度,发送信息的紧急程度:普通. ...

  5. ActiveMQ 安装异常

    解决方式: 1.确认计算机主机名名称没有下划线: 2.如果是win7,停止ICS(运行-->services.msc找到Internet Connection Sharing (ICS)服务,改 ...

  6. 在discuz二次开发模板时,diy编辑显示我“抱歉,您没有权限添加此模块

    <div id="diy_vk_portal_slide_top" class="area"><div id="frameCRxR0 ...

  7. SQLite详解

    一.新建SQLite操作类(继承SQLiteOpenHelper) public class SQLiteTest extends SQLiteOpenHelper { final static St ...

  8. java 1G大文件复制

    对比几种复制方法 复制的文件是980m的txt文件 1.  FileChannel 方法 代码: public static void mappedBuffer() throws IOExceptio ...

  9. YTU 3019: 螺旋方阵

    3019: 螺旋方阵 时间限制: 1 Sec  内存限制: 128 MB 提交: 2  解决: 2 题目描述 以下是一个5*5阶螺旋方阵.设计一个程序,输出该形式的n*n阶方阵(顺时针方向旋进).   ...

  10. Doubles 分类: POJ 2015-06-12 18:24 11人阅读 评论(0) 收藏

    Doubles Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19954   Accepted: 11536 Descrip ...