Stored Procedures
Stored Procedures: 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 58 of 96
Stored Procedures
Setup & Connect ✓ → Architecture & SQL ✓ → DBA & Tuning → Projects
DBA & Tuning · 3 — Production · ~10 min · Oracle — SQL & PL/SQL
What is this?
A stored procedure is named PL/SQL code stored in the database. Apps call it to run business steps (validate, update, commit) in one place.
Why should you care?
Banks prefer procedures for money movement so rules stay in OracleCore, not copied in five microservices.
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 PROCEDURE credit_account (
p_customer_id IN NUMBER,
p_amount IN NUMBER
) AS
BEGIN
IF p_amount <= 0 THEN
RAISE_APPLICATION_ERROR(-20001, 'Amount must be positive');
END IF;
UPDATE customers
SET balance = balance + p_amount
WHERE customer_id = p_customer_id;
IF SQL%ROWCOUNT = 0 THEN
RAISE_APPLICATION_ERROR(-20002, 'Customer not found');
END IF;
COMMIT;
END;
/
-- Call it
BEGIN
credit_account(1, 500);
END;
/
What happened?
- Parameters are IN values.
- RAISE_APPLICATION_ERROR stops bad input.
- UPDATE changes balance.
- SQL%ROWCOUNT checks if a row was updated.
Practice next
- Create the customers table if needed.
- Compile the procedure (F5 in SQL Developer).
- Call credit_account and SELECT the balance.
- Add a debit_account procedure.
- Log the operation into an audit table.
Remember
Procedures encapsulate business steps. Validate inputs before UPDATE. Test both success and error paths.
Teller credit
Branch deposits must update balance with the same rules every time.
Outcome: One procedure call from the app; consistent validation.
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!