Packages
Packages: 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 60 of 96
Packages
Setup & Connect ✓ → Architecture & SQL ✓ → DBA & Tuning → Projects
DBA & Tuning · 3 — Production · ~10 min · Oracle — SQL & PL/SQL
What is this?
A package groups related procedures and functions with a specification (public API) and a body (implementation).
Why should you care?
Large OracleCore modules (payments, KYC, billing) ship as packages so teams share one API.
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 PACKAGE account_pkg AS
PROCEDURE credit(p_id NUMBER, p_amount NUMBER);
FUNCTION get_bal(p_id NUMBER) RETURN NUMBER;
END account_pkg;
/
CREATE OR REPLACE PACKAGE BODY account_pkg AS
PROCEDURE credit(p_id NUMBER, p_amount NUMBER) AS
BEGIN
UPDATE customers SET balance = balance + p_amount WHERE customer_id = p_id;
COMMIT;
END;
FUNCTION get_bal(p_id NUMBER) RETURN NUMBER AS
v NUMBER;
BEGIN
SELECT balance INTO v FROM customers WHERE customer_id = p_id;
RETURN v;
END;
END account_pkg;
/
BEGIN
account_pkg.credit(1, 100);
END;
/
SELECT account_pkg.get_bal(1) FROM dual;
What happened?
- The package spec lists what others can call.
- The body contains the code.
- Call with package_name.procedure_name.
Practice next
- Create the package spec, then the body.
- Call credit and get_bal.
- Describe account_pkg in SQL Developer.
- Add a constant MIN_AMOUNT in the package.
- Grant EXECUTE on account_pkg to a app user.
Remember
Packages bundle related APIs. Spec = contract; body = code. Call as package.member.
Payments API
Channel apps must not invent their own UPDATE statements.
Outcome: They call account_pkg only.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!