Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

PL/SQL & T-SQL (Oracle and SQL Server) Module 12

Triggers in Oracle interview questions

Interview questions on triggers in Oracle: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

8 questions: 3 warm-ups and 5 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    How does a row trigger differ from a statement trigger?

    Answered in the lesson Oracle DML triggers: row, statement, INSTEAD OF

  2. Fresher to mid

    When does :OLD or :NEW hold nothing?

    Answered in the lesson Oracle DML triggers: row, statement, INSTEAD OF

  3. Mid

    What is a mutating table, and which triggers does the rule apply to?

    Answered in the lesson Compound triggers and the mutating-table error

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to senior

    A BEFORE UPDATE trigger on stock recalculates a discount for every row it fires on, and a nightly job that only corrects the on_hand count now changes prices too. The trigger was meant to run only when unit_price changes. Explain what went wrong and how you would scope the trigger.

    What it tests
    Whether the candidate knows a row trigger fires for every affected row, and can scope it with a column list (UPDATE OF), an UPDATING('col') test and a WHEN clause.
    First step
    The trigger has no column list and no UPDATING test, so it runs its discount logic even when only on_hand changes. Scope it to the price with BEFORE UPDATE OF unit_price and guard the body with UPDATING('UNIT_PRICE').
    Follow-ups

    From the lesson Oracle DML triggers: row, statement, INSTEAD OF

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    A teammate sees three BEFORE INSERT triggers on orders: one fills a surrogate key from a sequence, one defaults the order date, and one rejects a non-positive quantity. Which of the three would you replace, and with what?

    What it tests
    Whether the candidate prefers declarative features over triggers: identity columns, DEFAULT ON NULL and CHECK constraints, and can say what each guarantees that a trigger does not.
    First step
    All three can be declarative. The key becomes GENERATED ALWAYS AS IDENTITY, the date a DEFAULT ON NULL, and the quantity rule a CHECK (qty > 0) constraint, each enforced by the engine itself, on every path into the table.
    Follow-ups

    From the lesson Oracle DML triggers: row, statement, INSTEAD OF

    Model answer, Pro.

    In the answer:

    • Model answer
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    A row trigger on accounts keeps each customer's total at or below a cap with SELECT SUM(balance) for the row's customer. Its first test, a 10 % interest UPDATE, fails with ORA-04091 although no customer goes over. Explain the error and rewrite the check.

    What it tests
    Whether the candidate knows the mutating-table restriction on row triggers, can explain why a halfway read is unreliable, and can move the check into a compound trigger's statement section.
    First step
    The row trigger queries the table its own UPDATE is changing, which a row-level trigger may not do. Keep the per-row part to recording which customers changed, and do the SUM after the statement, in the AFTER STATEMENT section of a compound trigger.
    Follow-ups

    From the lesson Compound triggers and the mutating-table error

    Model answer, Pro.

    In the answer:

    • Model answer
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Mid to staff

    To get past ORA-04091, a teammate added PRAGMA AUTONOMOUS_TRANSACTION to the row trigger that enforces a balance cap. The error is gone and the existing tests pass. What would you check, and what would you ship instead?

    What it tests
    Whether the candidate knows an autonomous transaction reads only committed data, can name a statement that breaks the rule and still passes, and knows the other costs of autonomous triggers.
    First step
    Write a test that must fail: a deposit that takes one customer above the cap. With the autonomous trigger it passes, because the trigger's query reads the committed balances, not the row the statement has just changed.
    Follow-ups

    From the lesson Compound triggers and the mutating-table error

    Model answer, Pro.

    In the answer:

    • Model answer
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Senior to staff

    You must add an AFTER LOGON ON DATABASE trigger that records every new session. How do you make sure a bug in it cannot lock users out, and how do you test it before anyone depends on it?

    What it tests
    Whether the candidate knows an unhandled error in a logon trigger refuses the logon for users without ADMINISTER DATABASE TRIGGER, designs the handler for that, and tests with a privileged session open.
    First step
    Start from the failure: an unhandled error rolls back the triggering statement, and for a logon trigger that statement is the logon. Keep the body to one insert, decide what an error should mean, and reproduce a failure in a lab with a privileged session open.
    Follow-ups

    From the lesson Compound triggers and the mutating-table error

    Model answer, Pro.

    In the answer:

    • Model answer
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All PL/SQL & T-SQL (Oracle and SQL Server) interview questions · The PL/SQL & T-SQL (Oracle and SQL Server) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.