Est. 1991 Intermediate

PL/SQL

Oracle's procedural extension to SQL, a block-structured, Ada-influenced language for writing stored procedures, functions, packages, and triggers that run inside the Oracle Database.

Created by Oracle Corporation

Paradigm Procedural, imperative; block-structured; embedded in SQL
Typing Static, strong; based on Oracle SQL data types
First Appeared 1991 (with Oracle Database 6); PL/SQL 1.0
Latest Version Ships with each Oracle Database release; Oracle Database 23ai was released May 2, 2024

PL/SQL (Procedural Language/SQL) is Oracle’s procedural extension to the SQL query language. It wraps ordinary SQL in the control structures of a conventional programming language — variables, assignments, loops, conditionals, and exception handling — so that complex logic can be packaged and executed inside the Oracle Database itself as stored procedures, functions, packages, and triggers. Where plain SQL describes what data to retrieve or change, PL/SQL lets developers describe how a sequence of database operations should be carried out, all within a single, server-side, transaction-aware program unit.

History and Origins

PL/SQL grew out of work that began at Oracle Corporation around 1987, when the first lines of the PL/SQL compiler were written. The language first reached users in 1991, when PL/SQL 1.0 was bundled with the Oracle Database as part of the Transaction Processing Option for Oracle 6. This earliest version was deliberately modest: it offered flow-of-control statements and scalar data types but could not yet define stored procedures, manipulate arrays, or perform operating-system input and output.

The designers modeled PL/SQL’s syntax on Ada — the strongly typed, block-structured language developed for the U.S. Department of Defense — which in turn drew its lineage from Pascal. That heritage is visible throughout PL/SQL: its DECLARE/BEGIN/EXCEPTION/END blocks, its strong static typing, its package construct (echoing Ada packages), and its %TYPE/%ROWTYPE anchored declarations all reflect Ada-style design.

The language matured rapidly with the Oracle 7 family. PL/SQL 2.0, shipped with Oracle 7 in 1992, was a turning point: it added stored procedures, functions, packages, and database triggers, transforming PL/SQL from a scripting convenience into a full server-side programming environment. The 2.1, 2.2, and 2.3 point releases tracked Oracle 7.1 through 7.3, refining collections, records, and dynamic SQL.

Design Philosophy

PL/SQL is built around a few guiding ideas:

  • Reduce round trips. By moving procedural logic into the database server, a block of computation that would otherwise require many client-to-server SQL statements can execute as a single call, with intermediate results staying inside the database. This matters most over high-latency connections and for high-volume transaction processing.
  • First-class access to SQL. SQL statements are written directly in the language rather than through a separate API. Query results flow into variables and records, and values from variables substitute seamlessly into SQL.
  • Block structure. Every PL/SQL program is organized into blocks of the form DECLARE ... BEGIN ... EXCEPTION ... END. Blocks nest, each introducing its own scope of declared variables, and the optional EXCEPTION section provides structured error recovery.
  • Tight type integration. Variables are declared with Oracle’s own SQL data types. Anchored declarations such as %TYPE and %ROWTYPE let a variable automatically adopt the type of a table column or an entire row, so code stays correct when the schema changes.
  • Packaging and encapsulation. Related procedures, functions, types, and variables are grouped into packages with a public specification and a private body — a unit of modularity that also improves performance by loading and caching code together.

Key Features

A typical PL/SQL routine combines declarations, ordinary SQL, and control flow:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
CREATE OR REPLACE FUNCTION sales_tax(p_subtotal NUMBER)
    RETURN NUMBER
IS
    c_rate CONSTANT NUMBER := 0.06;
BEGIN
    RETURN p_subtotal * c_rate;
EXCEPTION
    WHEN OTHERS THEN
        RETURN 0;
END sales_tax;
/

The language’s notable capabilities include:

  • Control structuresIF/THEN/ELSIF/ELSE, CASE, and several loop forms (LOOP, WHILE, numeric and cursor FOR), plus EXIT and CONTINUE.
  • Stored program units — procedures, functions, packages, and triggers, all stored in compiled form inside the database and callable from SQL or other PL/SQL.
  • Records and collectionsRECORD types group related fields; collection types (associative arrays, nested tables, and VARRAYs) provide array-like structures.
  • Cursors — explicit cursors and FOR ... IN (SELECT ...) loops iterate over query result sets row by row, with cursor attributes such as %FOUND and %ROWCOUNT.
  • Exception handling — the EXCEPTION block traps predefined errors (such as NO_DATA_FOUND or ZERO_DIVIDE) and user-defined exceptions, enabling clean error recovery.
  • Bulk operationsBULK COLLECT and FORALL (introduced in Oracle8i) batch many rows between the PL/SQL and SQL engines in one context switch, a major performance optimization for set-oriented work.
  • Dynamic SQL — native dynamic SQL via EXECUTE IMMEDIATE, plus the older DBMS_SQL package, build and run statements assembled at runtime.
  • Triggers — trigger bodies fire on data or DDL events with access to affected rows through the :NEW and :OLD pseudo-records.

Evolution

PL/SQL has matured alongside the Oracle Database rather than through standalone releases. After Oracle8 synchronized the language’s version numbers with the database in 1997 (and added object types and methods), each subsequent database release extended PL/SQL:

  • Oracle8i (1999) added bulk SQL (BULK COLLECT, FORALL) and native dynamic SQL (EXECUTE IMMEDIATE).
  • Oracle9i (2001) introduced PL/SQL native compilation — translating procedural code into native machine code through a C compiler to accelerate computation-heavy logic — and brought object-type inheritance in Release 2.
  • Oracle Database 11g added real native compilation that no longer required an external C toolchain and function result caching (Release 1, 2007), plus edition-based redefinition for online upgrades (Release 2, 2009). (The PL/SQL optimizing compiler had been introduced earlier, in Oracle Database 10g.)
  • Oracle Database 12c (2013) allowed PL/SQL functions and procedures to be declared directly in a SQL statement’s WITH clause and raised several size limits.
  • Oracle Database 23ai (2024) added the SQL_TRANSPILER, which automatically converts eligible PL/SQL functions into equivalent SQL expressions for better optimization, among other in-database programming enhancements.

Because the language ships with the server, its effective “version” tracks the Oracle Database release. The latest long-term release, Oracle Database 23ai, became generally available on May 2, 2024.

Current Relevance

PL/SQL remains one of the most widely deployed procedural database languages in the world, a direct consequence of Oracle’s dominant position in enterprise relational databases. Banking, telecommunications, government, and large-scale ERP systems run substantial business logic in PL/SQL packages and triggers. Oracle’s own products lean on it heavily: E-Business Suite implements much of its logic in PL/SQL, and Oracle APEX, Oracle’s low-code application platform, is built around PL/SQL for server-side processing.

The language’s influence also reaches beyond Oracle. PostgreSQL’s PL/pgSQL was deliberately modeled on PL/SQL to ease adoption and migration, and IBM Db2 (from version 9.7) and Oracle’s TimesTen in-memory database both added PL/SQL compatibility so that existing Oracle procedures could run with minimal change. PL/SQL also relates to the ISO SQL/PSM standard for persistent stored modules, which standardizes the broader idea of a procedural language embedded in SQL.

Why It Matters

PL/SQL helped define what it means to put logic close to the data. By embedding a strongly typed, Ada-influenced procedural language directly inside the database — and giving SQL first-class status within it — Oracle gave enterprises a way to enforce correctness, performance, and atomicity in the same transaction that touched the data. That model proved durable enough to be imitated by competitors and standardized by ISO, and it remains central to how some of the largest production systems in the world are built. More than three decades after PL/SQL 1.0, the language is still the default tool for server-side programming in the Oracle ecosystem.


Sources: PL/SQL — Wikipedia; PL/SQL — Oracle FAQ; A (Not So) Brief But (Very) Accurate History of PL/SQL — Oracle Internals; The Origins of PL/SQL — Oracle PL/SQL Programming, O’Reilly; Oracle Database 23ai New Features Guide.

Timeline

around 1987
Development of the PL/SQL compiler begins at Oracle; the language's syntax is modeled on Ada, with its block structure and strong typing tracing back through Ada to Pascal.
1991
PL/SQL 1.0 is first included with the Oracle Database as part of the Transaction Processing Option for Oracle 6; this early version supports flow-of-control and scalar types but lacks stored procedures and operating-system I/O.
1992
PL/SQL 2.0 ships with Oracle 7, adding stored procedures, functions, packages, and database triggers — server-side program units stored and executed inside the database.
around 1993–1996
Incremental releases track the Oracle 7 line: PL/SQL 2.1 with Oracle 7.1, 2.2 with Oracle 7.2, and 2.3 with Oracle 7.3, refining collections (PL/SQL tables), records, and dynamic SQL.
1997
Oracle8 introduces object-oriented features (object types and methods) into PL/SQL; from this release the language's version numbers are synchronized with the database version.
1999
Oracle8i adds bulk SQL operations (BULK COLLECT and FORALL) and native dynamic SQL via the EXECUTE IMMEDIATE statement, substantially improving performance for set-oriented work.
2001
Oracle9i introduces PL/SQL native compilation, translating procedural code into native machine code (via C) to speed up computation-heavy logic; inheritance and other object enhancements arrive in 9i Release 2.
2007
Oracle Database 11g Release 1 adds real native compilation (no external C compiler required) and PL/SQL function result caching, improving execution of computation-heavy code.
2009
Oracle Database 11g Release 2 adds edition-based redefinition for online application upgrades; around the same period IBM Db2 9.7 introduces PL/SQL compatibility to ease migration off Oracle.
2013
Oracle Database 12c adds the ability to define PL/SQL functions and procedures directly in a SQL statement's WITH clause, and increases VARCHAR2 limits, tightening the integration between SQL and PL/SQL.
2024
Oracle Database 23ai is released (May 2, 2024), adding PL/SQL features such as the SQL_TRANSPILER (automatically translating eligible PL/SQL functions into SQL expressions) and broader in-database programming options alongside SQL and JavaScript.

Notable Uses & Legacy

Oracle E-Business Suite and enterprise applications

Large Oracle application suites such as E-Business Suite implement extensive business logic in PL/SQL packages and triggers running inside the database, keeping complex transactional rules close to the data.

Oracle APEX (Application Express)

Oracle's low-code web development platform is built on PL/SQL: page processing, validations, and server-side logic are written as PL/SQL stored in the database, with the framework itself authored largely in the language.

Stored procedures, packages, and triggers

Across banking, telecom, and government systems, PL/SQL packages encapsulate validation, auditing, and batch data transformations as server-side units, reducing client-server round trips and enforcing rules centrally.

Database triggers and integrity logic

PL/SQL trigger bodies react to INSERT, UPDATE, and DELETE events to maintain audit trails, derived columns, and cross-table constraints, with access to the affected rows through the :NEW and :OLD pseudo-records.

Db2 and TimesTen PL/SQL compatibility

IBM Db2 (from version 9.7) and Oracle's TimesTen in-memory database support PL/SQL, allowing procedures written for Oracle to run with minimal change and easing migration between platforms.

Language Influence

Influenced By

Influenced

Running Today

Run examples using the official Docker image:

docker pull gvenzl/oracle-free

Example usage:

docker run --rm -e ORACLE_PASSWORD=secret gvenzl/oracle-free
Last updated: