Professional Documents
Culture Documents
Store Procedure & Triggers: Nguyen Thi Kim Tuyen Huynh Nguyen Hong Nhan
Store Procedure & Triggers: Nguyen Thi Kim Tuyen Huynh Nguyen Hong Nhan
Store Procedure & Triggers: Nguyen Thi Kim Tuyen Huynh Nguyen Hong Nhan
Procedure &
Triggers
Nguyen Thi Kim Tuyen
Huynh Nguyen Hong Nhan
Agenda
Store Procedure
• Definition
• Parts / Parameters
• Structure
• Case study
Trigger
◈ OUT
🞚 OUT parameter returns a value to the calling program.
🞚 You can change its value and reference the value after assigning it.
◈ IN OUT
🞚 IN OUT parameter passes an initial value to a subprogram and returns an updated value
to the caller.
Structure of Store Procedure
1. Declarative
2. Execution
3. Exception-handling
Sample
Database Schema
Option 1
Option 2
Generalized Model for Active
Databases
● Active database is a database consisting of set of
active rules / triggers.
● Disadvantages
○ Active DBs are very difficult to be maintained of
the complexity that arises in understanding the effect
of these active rules/ triggers.
● Advantages
○ Enhances traditional DB functionalities with powerful
rule processing capabilities
● Avoids redundancy of checking & repair operations
● Enable a uniform & centralized description of business rules
relevant to the information system.
● Suitable platform for building large & efficient
knowledge base & expert systems
Source: https://www.geeksforgeeks.org/active-databases/
Generalized Model for Active
Databases and Oracle Triggers
● Event-Condition-Action (ECA) model specifies active database rules. A
rule has 3 components:
○ Event: triggers the rule. E.g database update operations, temporal events,
external events.
○ Condition: determines whether the rule action should be executed.
○ Action: to be taken. E.g: SQL scripts, a database transaction, external
program.
● Oracle triggers - active rules is a named PL/SQL block stored in the Oracle
Database and executes automatically when a triggering event takes place.
● The event can be:
○ A DML statement executes. E.g. INSERT, UPDATE, DELETE
○ A DDL statement executes. E.g. CREATE or ALTER
○ A system event such as startup or shutdown of the Oracle Database.
○ A user event such as login or logout.
Oracle Triggers
Trigger Examples (1)
The Total_sal attribute
is a derived attribute =
sum of salaries of all
employees belong to
the particular
department
6. https://www.oracletutorial.com/plsql-tutorial/oracle-disable-triggers/
7. https://www.oracletutorial.com/plsql-tutorial/oracle-statement-level-triggers/
8. https://docs.oracle.com/cd/B19306_01/server.102/b14220/triggers.htm
9. Ramez Elmasri , Shamkant Navathe Fundamentals of Database Systems 7th Edition