A script-enabled browser is required for this page to function properly.

About Writing Trigger Code

The code in Oracle Forms triggers and menu item commands is written in Oracle's PL/SQL language. PL/SQL is an extension to the SQL database language, and both SQL statements and PL/SQL statements may be included in a Oracle Forms trigger. Calls to Oracle Forms Built-in subprograms and to user-named PL/SQL subprograms are permitted.

Calling PL/SQL procedures within a PL/SQL trigger behaves as if the entire procedure text were substituted in-line at the place in the trigger that call to the procedure exists. Any exception (including FORM_TRIGGER_FAILURE) will follow normal PL/SQL exception handler scoping rules

The text of a Oracle Forms trigger is an anonymous PL/SQL block. A block can consist of three sections:

  1. a declaration section for variables, constants, cursors, and exceptions
  2. a section of executable statements
  3. a section of exception handlers

The syntax for delimiting the sections of a PL/SQL block looks like this:

DECLARE
 -- declarative statements (optional)
BEGIN
 -- executable statements (required)
EXCEPTION
 -- exception handlers (optional)
END;

In a trigger, only the executable section is required. A trigger that does not have a DECLARE section, does not need the BEGIN and END keywords, as they are added implicitly. The following example shows such a trigger:


/* Key-CLRREC Trigger: */ 
   IF :System.Record_Status = 'CHANGED' OR
      :System.Record_Status = 'INSERT' THEN 
      Commit_Form; 
   END IF; 
   Clear_Record; 

However, if you include a DECLARE section, you must also include the BEGIN and END keywords so the compiler can detect the start of the executable section:


/* When-Button-Pressed Trigger: */ 
   DECLARE 
    discount_variable NUMBER (5); 
   BEGIN 
    SELECT discount 
    INTO discount_variable from
    FROM Promotions 
    WHERE custid = :cust_id; 
    :total := calculate_total(:amount, discount_variable); 
   END; 

Types of Events

Trigger Definition Level and Scope

Creating a trigger in the Object Navigator

Setting trigger properties

About compiling triggers

About writing SQL statements in triggers

Overview of trigger categories

About PL/SQL in Oracle Forms