Triggers are blocks of PL/SQL code that are written to perform tasks when a specific event occurs within an application. In effect, an Oracle Forms trigger is an event-handler written in PL/SQL to augment (or occasionally replace) the default processing behavior. Every trigger has a name, and contains one or more PL/SQL statements. A trigger encapsulates PL/SQL code so that it can be associated with an event and executed and maintained as a distinct object.

Block Processing Triggers:

Block processing triggers fire in response to events related to record management in a block.
When-Create-RecordPerform an action whenever Oracle Forms attempts to create a new record in a block.When-Clear-BlockPerform an action whenever Oracle Forms flushes the current block; that is, removes all records from the block.When-Database-RecordPerform an action whenever Oracle Forms changes a record’s status to Insert or Update, thus indicating that the record should be processed by the next COMMIT_FORM operation.

Interface Event Triggers:

Interface event triggers fire in response to events that occur in the form interface. Some of these triggers, such as When-Button-Pressed, fire only in response to operator input or manipulation. Others, like When-Window-Activated, can fire in response to both operator input and programmatic control.
When-Button-PressedInitiate an action when an operator selects a button, either with the mouse or through keyboard selection.When-Checkbox-ChangedInitiate an action when the operator toggles the state of a check box, either with the mouse or through keyboard selection.When-Image-ActivatedInitiate an action whenever the operator double-clicks an image item.When-Image-PressedInitiate an action whenever an operator clicks on an image item.When-Radio-ChangedInitiate an action when an operator changes the current radio button selected in a radio group item.When-Window-ActivatedInitiate an action whenever an operator or the application activates a window.When-Window-ClosedInitiate an action whenever an operator closes a window with the window manager’s Close command.When-Window-DeactivatedInitiate an action whenever a window is deactivated as a result of another window becoming the active window.

Master/Detail Triggers:

Oracle Forms generates master/detail triggers automatically when a master/detail relation is defined between blocks. The default master/detail triggers enforce coordination between records in a detail block and the master record in a master block. Unless developing custom block-coordination schemes, you do not need to define these triggers.
On-Check-Delete-MasterFires when Oracle Forms attempts to delete a record in a block that is a master block in a master/detail relation.On-Clear-DetailsFires when Oracle Forms needs to clear records in a block that is a detail block in a master/detail relation because those records no longer correspond to the current record in the master block.On-Populate-DetailsFires when Oracle Forms needs to fetch records into a block that is the detail block in a master/detail relation so that detail records are synchronized with the current record in the master block.

Message-Handling Triggers:

Oracle Forms automatically issues appropriate error and informational messages in response to runtime events. Message handling triggers fire in response to these default messaging events.
On-ErrorReplace a default error message with a custom error message, or to trap and recover from an error.On-MessageTo trap and respond to a message; for example, to replace a default message issued by Oracle Forms with a custom message.

Validation Triggers:

Validation triggers fire when Oracle Forms validates data in an item or record. Oracle Forms performs validation checks during navigation that occurs in response to operator input, programmatic control, or default processing, such as a Commit operation.
When-Validate-ItemWhen-Validate-Record

Navigational Triggers:

Navigational triggers fire in response to navigational events. Navigational triggers can be further sub-divided into two categories: Pre-and Post-triggers, and When-New-Instance triggers. Pre-and Post- Triggers fire as Oracle Forms navigates internally through different levels of the object hierarchy. When-New-Instance-Triggers fire at the end of a navigational sequence that places the input focus on a different item.
Pre-FormPerform an action just before Oracle Forms navigates to the form from “outside” the form, such as at form startup.Pre-BlockPerform an action before Oracle Forms navigates to the block level from the form level.Pre-RecordPerform an action before Oracle Forms navigates to the record level from the block level.Pre-Text-ItemPerform an action before Oracle Forms navigates to a text item from the record level.Post-Text-ItemManipulate an item when Oracle Forms leaves a text item and navigates to the record level.Post-RecordManipulate a record when Oracle Forms leaves a record and navigates to the block level.Post-BlockManipulate the current record when Oracle Forms leaves a block and navigates to the form level.Post-FormPerform an action before Oracle Forms navigates to “outside” the form, such as when exiting the form.When-New-Form-InstancePerform an action at form start-up. (Occurs after the Pre-Form trigger fires).When-New-Block-InstancePerform an action immediately after the input focus moves to an item in a block other than the block that previously had input focus.When-New-Record-InstancePerform an action immediately after the input focus moves to an item in a different record.When-New-Item-InstancePerform an action immediately after the input focus moves to a different item.

Transactional Triggers:

Transactional triggers fire in response to a wide variety of events that occur as a form interacts with the data source.
On-DeleteOn-InsertOn-UpdateOn-LogonOn-LogoutPost-Database-CommitPost-DeletePost-InsertPost-UpdatePre-CommitPre-DeletePre-InsertPre-Update

Query-Time Triggers:

Query-time triggers fire just before and just after the operator or the application executes a query in a block.
Pre-QueryValidate the current query criteria or provide additional query criteria programmatically, just before sending the SELECT statement to the database.Post-QueryPerform an action after fetching a record, such as looking up values in other tables based on a value in the current record. Fires once for each record fetched into the block.
打开,关闭,创建,更新记录的trigger次序
PRE-……
在进入一个form,或是导航到一个新的block时触发,PRE-……系列的触发器一般是在WHEN-NEW-……-INSTANCE系列之前,它们如果失败了的话,就不能成功导航到下一个对象了,只能留在当前的位置。在这些触发器里可以设置一些判断条件来限制是否可以导航到新的位置。
WHEN-NEW-……-INSTANCE
这一类的trigger都是当鼠标光标每次落到一个新的block,record,item上时触发的,而且就算失败了,也不会发生什么错误。但是when-new-form-instance,只有当form启动时,光标导航到第一个导航块的第一个导航item时触发,如果一个应用有多个form,当光标在各个form之间转换时,并不会触发它。
POST-TEXT-ITEM和WHEN-VALIDATE-ITEM
Post-text-item的触发点:当输入的光标从一个Text-Item 转到其它item,可以用它来改变item的值,而when-Validate-item虽然也是在离开前触发,但是作用不同,Post-Text-Item本身是没有验证的,when-Validate-item可以用来补充一些验证(除了form本身的验证),但是当form验证成功以后,会把item标志为‘valid’,而不会再去验证了,如果这时我们再去修改它的值,那么就有可能会把无效的值导入到数据库。在创建和更新一条记录时,先触发when-Validate-item,再触发Post-Text-Item,然后是when-Validate-record。
POST-……系列的都是离开当前的block,record,item时触发的
WHEN-WINDOW-ACTIVATED
做原材料属性修改平台时,第一次使用这个触发器,用来从另一个window返回时,刷新当前window,代码写在了这个触发器里。使用之前用fnd_message.debug试验了一下,打开窗口后不停的弹出message。只要这个窗口在活动期间就会不停的执行这个触发起里面的代码,所以执行的代码应该用if条件限制一下。
Form的Trigger的优先级是从item,到block,到form级别,如果另外设置Execution Hierarch属性(override,before,after),则按照设置后的顺序执行。如果是override的话,则执行完这个级别的触发器,就不往上执行了,before就是执行完这个级别的触发器后,如果上一个级别也有这个触发器的话,继续去执行,after就是先去执行上一个级别的触发器,然后再回来执行。感觉触发器比较难理解的还是每一种触发器触发的时间,和在开发中怎么使用。目前了解的就是pre-…,when-new-…-instance,when-…-validate,post-query和几个on-…