---
title: "How to Create Trigger in PLSQL Procedure Best Example"
description: "Best example to create Trigger in SQL projects. Also given types of Triggers."
url: https://srinimf.com/2013/12/30/plsql-create-trigger/
date: 2013-12-30
modified: 2021-09-24
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2013/12/pexels-photo-6532588.jpeg?fit=1880%2C1253&ssl=1
categories: ["PL/SQL"]
tags: ["Example to Create Trigger", "Oracle PL/SQL", "SQL tips and tricks"]
type: post
lang: en
---

# How to Create Trigger in PLSQL Procedure Best Example

Triggers are database procedures. These will be fired implicitly, when certain thing happens. 

## Create Triger Example

CREATE OR REPLACE TRIGGER** my_sal_changes**
BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab
FOR EACH ROW
WHEN (new.Empno > 0)
**DECLARE**
    sal_diff number;
** BEGIN**
    sal_diff  := :new.sal  – :old.sal;
    dbms_output.put(‘Old salary: ‘ || :old.sal);
    dbms_output.put(‘  New salary: ‘ || :new.sal);
    dbms_output.put_line(‘  Difference ‘ || sal_diff);
**END;**
** /**

The size of the Trigger should not exceed 32K.

## Important Points

Trigger will work on DML operations, INSERT,DELETE,UPDATE

BEFORE/AFTER key words. When trigger has to execute, we need to given in definition

FOR EACH ROW => Trigger validates for each row

INSTEAD OF key word we need to use for views

## Types of Triggers

- DML triggers on tables.
- `INSTEAD` `OF` triggers on views.
- System triggers on `DATABASE` or `SCHEMA`: With `DATABASE`, triggers fire for each event for all users; with `SCHEMA`, triggers fire for each event for that specific user.

Related articles

- [PL/SQL – Complex Queries (Job Interviews)](http://srinimf.com/2013/12/08/plsql-complex-queries-job-interviews/) (srinimf.com)
- [PL/SQL – Difficult Questions](http://srinimf.com/2013/12/12/plsql-difficult-questions/) (srinimf.com)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2013%2F12%2F30%2Fplsql-create-trigger%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2013%2F12%2Fpexels-photo-6532588.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Create%20Trigger%20in%20PLSQL%20Procedure%20Best%20Example)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2013/12/30/plsql-create-trigger/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2013/12/30/plsql-create-trigger/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2013/12/30/plsql-create-trigger/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2013/12/30/plsql-create-trigger/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Create%20Trigger%20in%20PLSQL%20Procedure%20Best%20Example&body=https%3A%2F%2Fsrinimf.com%2F2013%2F12%2F30%2Fplsql-create-trigger%2F&share=email)
-

### Like this:

Like Loading…
