Oracle7 Server Application Developer's Guide
When Triggers Are Compiled
In previous releases of the Oracle7 Server, triggers were basically like PL/SQL anonymous blocks, with the addition of the :NEW and :OLD capabilities. A PL/SQL anonymous block is compiled each time it is loaded into memory. Compilation involves three stages:
1. syntax checking: PL/SQL syntax is checked and a parse tree is generated
2. semantic checking: type checking and further processing on the parse tree
3. code generation: the pcode is generated
The CREATE TRIGGER statement creates a trigger, and stores its source in the data dictionary. In releases prior to 7.3, steps 1 and 2 are performed at CREATE TRIGGER time, so that syntactic and semantic errors can be reported back to the user who issued the CREATE TRIGGER command. However, the compiler output is discarded. At execution time, the source for the trigger is parsed and executed just like an anonymous PL/SQL block.
In Oracle7 release 7.3, triggers are fully compiled when the CREATE TRIGGER command is issued, and the pcode is stored in the data dictionary. Hence, firing the trigger no longer requires the opening of a shared cursor to run the trigger action. Instead, the trigger is executed directly.
If errors occur during the compilation of a trigger, the trigger is still created. If a DML statement fires this trigger, the DML statement will fail. (In both release 7.3 and releases 7.2 and earlier, runtime trigger errors always cause the DML statement to fail.) You can use the SHOW ERRORS command in SQL*Plus or Server Manager to see any compilation errors when you create a trigger, or you can SELECT the errors from the USER_ERRORS view.
Dependencies
Compiled triggers have dependencies. They become invalid if a depended-on object, such as a stored procedure or a function called from the trigger body, is modified. Triggers that are invalidated for dependency reasons are recompiled when next invoked.
You can examine the ALL_DEPENDENCIES view to see the dependencies for a trigger. For example, the statement
SELECT NAME, REFERENCED_OWNER, REFERENCED_NAME, REFERENCED_TYPE
FROM ALL_DEPENDENCIES
WHERE OWNER = 'SCOTT' and TYPE = 'TRIGGER';
shows the dependencies for the triggers in the SCOTT schema.
Recompiling a Trigger
Use the ALTER TRIGGER command to recompile a trigger manually. For example, the command
ALTER TRIGGER print_salary_changes COMPILE;
recompiles the PRINT_SALARY_CHANGES trigger
Migration Issues
Non-compiled triggers cannot be fired under compiled trigger releases (such as 7.3). If upgrading from a non-compiled trigger release to a compiled trigger release, all existing triggers must be compiled. The upgrade script cat73xx.sql invalidates all triggers so that they are automatically recompiled when first executed under the Oracle release 7.3 server. (The xx stands for a variable minor release number.)
Downgrading from 7.3 or later to a release prior to 7.3 requires that you execute the cat73xxd.sql downgrade script. This handles portability issues between stored and non-stored trigger releases.