Tutorials Oracle SQL Tutorial

Exception Handling

Exception Handling: 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 62 of 96

Exception Handling

Setup & Connect ✓Architecture & SQL ✓DBA & TuningProjects

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

What is this?

PL/SQL exception handling catches errors like NO_DATA_FOUND or ZERO_DIVIDE so your program can respond instead of crashing the session.

Why should you care?

Batch jobs in telecom billing must log bad rows and continue — not stop the whole night run.

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.

DECLARE
  v_bal NUMBER;
  v_id  NUMBER := 999;
BEGIN
  SELECT balance INTO v_bal FROM customers WHERE customer_id = v_id;
  DBMS_OUTPUT.PUT_LINE('Balance=' || v_bal);
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('Customer ' || v_id || ' not found');
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
    RAISE;
END;
/

What happened?

  • SELECT INTO expects exactly one row.
  • NO_DATA_FOUND runs if zero rows.
  • WHEN OTHERS is a safety net; RAISE re-throws after logging.

Practice next

  1. SET SERVEROUTPUT ON in SQL*Plus/SQL Developer.
  2. Run the block with a missing id.
  3. Change v_id to an existing customer.
  4. Raise a custom error with RAISE_APPLICATION_ERROR.
  5. Write the error into an error_log table.

Remember

Catch expected errors explicitly. Log SQLERRM for support. Do not hide failures in empty handlers.

Nightly billing batch

One bad account must not stop 2 million invoice rows.

Outcome: Handler logs the bad id and continues.

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