Tutorials Oracle SQL Tutorial

Functions

Functions: 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 59 of 96

Functions

Setup & Connect ✓Architecture & SQL ✓DBA & TuningProjects

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

What is this?

A function returns a value and is often used inside SQL SELECT lists. Procedures do work; functions compute and return.

Why should you care?

Tax calculations, fee formulas, and status labels are cleaner as Oracle functions reused in many queries.

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 OR REPLACE FUNCTION get_balance (
  p_customer_id IN NUMBER
) RETURN NUMBER AS
  v_bal NUMBER;
BEGIN
  SELECT balance INTO v_bal FROM customers WHERE customer_id = p_customer_id;
  RETURN v_bal;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    RETURN NULL;
END;
/

SELECT customer_id, full_name, get_balance(customer_id) AS bal
FROM customers;

What happened?

  • RETURN NUMBER defines the result type.
  • SELECT INTO loads one value.
  • EXCEPTION handles missing customers.
  • You can call the function from SQL.

Practice next

  1. Compile get_balance.
  2. Select from customers using the function.
  3. Call get_balance(999) and confirm NULL.
  4. Return 0 instead of NULL for missing customers.
  5. Add a city parameter filter function.

Remember

Functions return values; great in SELECT. Handle NO_DATA_FOUND. Keep functions side-effect free when used in SQL.

Balance widget

Mobile app shows balance via a single function used by web and batch jobs.

Outcome: One formula, many callers.

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. How to structure your answer (60–90 seconds) Define SQL queries in plain languag…
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. How to structure your answer (60–90 seconds) Define Schema design in plain langu…
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. How to structure your answer (60–90 seconds) Define Transactions in plain langua…
Mid Detailed
Compare two approaches to Indexing—when would you choose each?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Indexing in plain language f…
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. How to structure your answer (60–90 seconds) Define Normalization in plain langu…
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