background image
<< Using EXCEPTION Statements | Types of Triggers >>
<< Using EXCEPTION Statements | Types of Triggers >>

Using Triggers

Using Triggers 5-1
5
Using Triggers
This chapter describes database triggers, which are stored procedural code that is
associated with a database table, view, or event.
This chapter contains the following sections:
"Designing Triggers"
on page 5-1
"Creating and Using Triggers"
on page 5-4
Designing Triggers
Triggers are stored procedural code that is fired automatically when specified events
happen in the database. Triggers are associated with tables, views, or events. Unlike
procedures and functions, triggers cannot be invoked directly. Instead, Oracle
Database implicitly fires triggers when a triggering event occurs, regardless of the user
or application. You may never be aware that a trigger is operating unless its operation
causes an error that is not handled properly, when the event that fired the trigger fails.
The correct use of triggers enables you to build and deploy applications that are more
robust, secure, and that use the database more effectively. These gains are possible
because triggers can deliver the following features:
Data integrity checking and enforcement
Auditing and logging
Complex business logic modeling
Transaction validity checking and enforcement
Derived column generation
Table modification enabling and restriction
You can use triggers to enforce low-level business rules that are inherent to the
database, and are therefore common for all client applications. For example, you may
have several client applications that access the
employees
table in the
hr
schema. If a
trigger on that table ensures the proper format of all data added to the table, this
business logic does not have to be reproduced and maintained in every client
application. Because the trigger cannot be circumvented by the client application, the
business logic stored in the trigger is used automatically.
Each trigger has the following general form:
TRIGGER
trigger_name
triggering_statement
[
trigger_restriction
]
BEGIN