You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
PL/SQL (Procedural Language/SQL) is Oracle's proprietary extension to SQL. It combines the data manipulation power of SQL with the procedural constructs of a programming language, and runs entirely inside the Oracle database engine.
Plain SQL is a declarative language — you describe what data you want, not how to get it. That's great for queries, but insufficient when you need:
PL/SQL fills all of these gaps.
PL/SQL code executes inside the Oracle database server, not in the application. This brings several benefits:
| Benefit | Detail |
|---|---|
| Performance | Multiple SQL statements execute in one round-trip |
| Security | Applications call named procedures instead of raw SQL |
| Maintainability | Business logic lives in the database, not scattered across apps |
| Portability | Any client can call the same stored procedure |
-- Plain SQL: single statement
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
-- PL/SQL: logic + multiple statements in one block
BEGIN
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
/
The PL/SQL version wraps both updates in a transaction with error handling — impossible with a single SQL statement.
PL/SQL blocks end with a forward slash (/) on its own line when run in SQL*Plus or SQL Developer scripts. This tells Oracle to execute the block.
Ready to write your first PL/SQL block? Let's go.