An Oracle trigger is a special type of stored procedure, which is different from the stored procedure. A trigger is executed when an event is triggered. trigger events can be divided into three categories: DML events, DDL events, and database events, stored procedures can be called directly by the stored procedure name. When performing operations such as UPDATE, INSERT, and DELETE on a table, SQL Server automatically runs the SQL statement defined by the trigger, this ensures that data processing must comply with the rules defined by these SQL statements.
A trigger is a code block automatically executed when a specific event occurs. It is similar to a stored procedure, but users cannot directly call them.
Trigger Function
1. Allow/restrict table modifications
2. automatically generate a derived column, such as an auto-increment Field
3. Forced Data Consistency
4. provide audit and logging
5. Prevent invalid transaction processing
6. Enable complex business logic
Trigger type
There are four types of triggers: 1. data Control Language (DML) triggers, 2. replace (instead of) Trigger, 3. data Definition Language (DDL) triggers, 4. database event triggers.
Data manipulation language (DML) triggers: DML triggers are defined on tables and created on tables. When writing a DML trigger, a trigger triggered by a DML event has two elements: 1. Determine the trigger table, that is, the table on which the trigger is defined. 2. determine the trigger event. The DML trigger event includes INSERT, UPDATE, and DELETE. The trigger is replaced by the instead of trigger, which is created on the view, it is used to replace the delete, insert, and modify operations on the view. The Data Definition Language (DDL) Trigger, referred to as the DDL trigger, is defined in the mode. The trigger event is the creation and modification of the data object; database event triggers are defined in the entire database or mode. A trigger event is a database event.
The syntax for ORACLE to generate database triggers is:
The following is a code snippet:
CREATE [or replace] TRIGGER name
{BEFORE | AFTER | instead of} trigger event 1 [OR trigger event 2...]
ON Table Name
WHEN trigger Condition
[For each row]
DECLARE
Declaration
BEGIN
Subject
END;