Tutorials Oracle SQL Tutorial

Triggers

Triggers: free step-by-step lesson with examples, common mistakes, and interview tips — part of Oracle SQL Tutorial on Toolliyo Academy.

On this page

Oracle SQL Tutorial · Lesson 61 of 96

Triggers

Setup & Connect ✓Architecture & SQL ✓DBA & TuningProjects

DBA & Tuning · 3 — Production · ~10 min · Oracle — SQL & PL/SQL

What is this?

A trigger is PL/SQL that runs automatically on INSERT/UPDATE/DELETE (or other events). Use for auditing and simple rules — not heavy business workflows.

Why should you care?

Regulators ask “who changed this balance?” — audit triggers on OracleCore tables answer that.

See it live — copy this example

Run these statements in SQL Developer or SQL*Plus against your lab PDB. Prefer a practice user — not SYS — for application SQL.

CREATE TABLE customers_audit (
  audit_id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  customer_id NUMBER,
  old_balance NUMBER,
  new_balance NUMBER,
  changed_at TIMESTAMP DEFAULT SYSTIMESTAMP,
  changed_by VARCHAR2(128)
);

CREATE OR REPLACE TRIGGER trg_customers_bal_au
AFTER UPDATE OF balance ON customers
FOR EACH ROW
BEGIN
  INSERT INTO customers_audit(customer_id, old_balance, new_balance, changed_by)
  VALUES (:OLD.customer_id, :OLD.balance, :NEW.balance, USER);
END;
/

UPDATE customers SET balance = balance + 50 WHERE customer_id = 1;
COMMIT;
SELECT * FROM customers_audit;

What happened?

  • :OLD and :NEW are the row values before/after the change.
  • AFTER UPDATE OF balance fires only when balance changes.
  • USER is the Oracle session user.

Practice next

  1. Create audit table and trigger.
  2. Update a balance and SELECT audit rows.
  3. Update full_name only and confirm no audit row.
  4. Also log INSERT events.
  5. Add a column action_type = 'UPDATE'.

Remember

Triggers fire automatically on DML. :OLD / :NEW hold before/after values. Prefer triggers for audit; prefer packages for business rules.

Balance audit trail

Compliance reviews every balance change for a disputed account.

Outcome: customers_audit shows old/new values and who changed them.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain SQL queries in the context of Oracle SQL.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define SQL queri…
Mid Detailed
What are common mistakes teams make with Schema design when using Oracle SQL?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Schema de…
Senior Detailed
How would you debug a production issue related to Transactions in a Oracle SQL application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Transacti…
Junior Detailed
Describe a real-world scenario where Normalization mattered in a Oracle SQL project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Normaliza…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Oracle SQL Tutorial
Course syllabus

Oracle SQL Tutorial

Oracle — Introduction & Environment Setup
Oracle — Database Startup & Connection
Oracle — Architecture & Internals
Oracle — Database Administration
Oracle — Security & User Management
Oracle — Tablespaces & Storage
Oracle — SQL & PL/SQL
Oracle — Backup, Recovery & Flashback
Oracle — Performance & High Availability
Oracle — Cloud & Modern Features
Oracle — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details