PL/SQL Demo Examples

Practice scripts, one file each. Every demo is self-contained and commented; run it with SQL*Plus, sqlcl, or any Oracle client. Scripts that build their own table drop it first, so they can be re-run safely.

How to use: click View to open a file in the code viewer, read its comments, download it, then run it against your database.

sqlplus user/password@db @01_hello.sql   # or: sqlcl user/password@db @01_hello.sql

Foundations

Variables, types, operators, and the two shapes of decision-making.

#DescriptionLink
1Hello, WorldView
2Declaring VariablesView
3Data Types & %TYPEView
4Operators & ExpressionsView

Control Flow

IF/CASE, loops, cursors, and exception handling.

#DescriptionLink
5IF/ELSIF and CASEView
6LOOP, WHILE, FORView
7Cursors & %ROWTYPEView
8Exception HandlingView

Functions, Procedures & Packages

Stored, reusable, named PL/SQL.

#DescriptionLink
9FunctionView
10ProcedureView
11Package SpecificationView
12Package BodyView
13Package Build/Test ScriptView

Advanced

Collections and triggers — the intermediate-to-expert features.

#DescriptionLink
14Collections (Associative Array, Nested Table, VARRAY)View
15Triggers (BEFORE INSERT, :NEW)View

Study Project: A Bitwise Utility Package

A complete spec/body/test trio — the professional three-file package pattern, compiled and exercised in one script.

#DescriptionLink
16bit_util — Package SpecificationView
17bit_util — Package BodyView
18bit_util — Build & Test ScriptView

Study Project: A Small Order Schema

A three-table schema plus the joins, aggregates, and a view built on top of it — ties together Build and Transform.

#DescriptionLink
19Build Schema (tables, constraints, seed data)View
20Transform / ETL (JOIN, GROUP BY, CTE, VIEW)View

Sample Data Files

Referenced from the Operate lesson's homework exercises.

FileUsed by
developer.csvOperate — DML: INSERT homework
members.csvOperate — SQL: WHERE homework
Practice move: after running each demo, change one thing on purpose — remove a WHEN OTHERS handler, drop the EXTEND call before assigning to a nested table, or comment out :NEW.price's check — and read the resulting error before fixing it.