PL / SQL – procedural programming language extends SQL
Pl/sql- like oops lagauge, developed by oracle,platform independently,fast
data manipulation.
Pl/sql architecture :The architecture can be thought of in two parts: Physical
architecture and Logical architecture.
Physical Architecture
Within the Oracle Database, there is a SQL engine and a PL/SQL
engine.
The SQL engine operates your SQL queries and returns data.
o It contains a SQL Statement Executor that performs
operations like inserts, updates, deletes, and query returns.
o Before a query runs, the SQL engine performs operations like
Parsing, Fetching, and Executing.
o It includes a SQL optimizer which optimizes queries based on a
selected optimization level.
o All your SQL operations are done in the SQL engine.
The PL/SQL engine is described as "a bit more complicated".
o It generally cooperates with the SQL Engine.
o If you perform any SQL operations inside your PL/SQL code, that
part is handled by the SQL engine.
o After SQL operations, the result is returned to the PL/SQL engine.
o Your PL/SQL code can then do any programmatically operations
using the returned results.
o PL/SQL has its own optimizer.
Logical Architecture and Flow/Integration
PL/SQL is tightly integrated with SQL.
When coding with PL/SQL and SQL together, it feels like coding with
one language because PL/SQL code resembles SQL. PL/SQL is "just like
the next step of SQL".
The PL/SQL Engine allows you to create, manage, and execute
SQL and PL/SQL codes and interact with the database.
When you write SQL code inside your PL/SQL code, the PL/SQL engine
calls the SQL engine to perform the operation.
Then, the result is sent back to the PL/SQL engine.
This operation of moving from one engine to another and back is called
context switches.
Context switches are very fast but too many can lead to performance
issues.
Logical Capabilities / Benefits Enabled by PL/SQL
Enables Subprograms: Allows saving and re-using code, avoiding
repetition and helping organize business logic. Subprograms can be
shared.
Dynamic Queries: Enables creating or changing SQL queries based
on variables within your program.
Case Insensitivity: PL/SQL is case-insensitive, though coding styles
are recommended for readability.
Optimizer: PL/SQL has its own optimizer to improve performance by
optimizing code before it runs.
Object-Oriented Programming: Enabled with abstract data types.
Web Development: Possible using the PL/SQL Gateway and Web
Toolkit, though other languages are often more suitable.
🔹 SQL Processing Flow (Low-Level, Oracle Internal)
🔸 Flow Steps:
1. Client Submits SQL
Sent via SQL*Plus, JDBC, etc.
2. Listener Accepts Connection
Oracle Net Listener transfers control to a dedicated/shared server
process.
3. SQL Statement Sent to SQL Engine
4. SQL Parser (SGA: Shared Pool)
o Lexical Analyzer: Tokenizes the SQL.
o Syntax Analyzer: Validates SQL grammar.
o Semantic Analyzer: Verifies table/column existence, types.
5. Optimizer (CBO)
o Uses stats from data dictionary.
o Generates execution plan with lowest cost path.
6. Row Source Generator
o Converts plan into executable steps.
7. SQL Execution Engine
o Executes plan using:
Buffer Cache (reads data blocks)
Redo/Undo Buffers if DML
8. Result Returned
o Rows are sent back via server process → listener → client.
🔸 Key Internal Components Involved:
SQL Engine
SGA (Shared Pool, Buffer Cache)
Cursor Cache
Data Dictionary
Redo/Undo Buffers (for DML)
🔹 PL/SQL Processing Flow (Low-Level, Oracle Internal)
🔸 Flow Steps:
1. Client Sends PL/SQL Block
(via SQL Developer, API, or Oracle Forms)
2. Listener Handles Request
Creates a server session.
3. PL/SQL Block Sent to PL/SQL Engine (PGA)
4. PL/SQL Parser & Compiler
o Parses full block (procedure/function/package).
o Compiles to Oracle bytecode.
o Stores in Data Dictionary if a stored unit.
5. PL/SQL Engine Executes Block
o Executes procedural logic (IF, LOOP, variables).
o Whenever SQL (SELECT/INSERT) occurs:
Calls SQL Engine internally.
Follows normal SQL processing steps.
6. Execution Context Created
o Includes Call Stack, Variable Table, Cursor Table.
7. Output Returned
o Via OUT parameters, DBMS_OUTPUT, etc.
🔸 Key Internal Components Involved:
PL/SQL Engine
PGA (stores logic context)
SQL Engine (for embedded SQLs)
Execution Context Area (ECA)
Call Stack, Variable Table, Cursor Table
Data Dictionary (if stored unit)
🔁 Key Difference:
SQL: Executes one statement directly in SQL Engine, stateless.
PL/SQL: Runs as a procedural program inside Oracle, uses both
PL/SQL Engine and SQL Engine together.
PLUGGABLE Database - multitenant architecture. Here are some crisp, short
notes about the Pluggable Database architecture, based on the sources
provided:
multitenant architecture, was introduced starting with Oracle
database version 12c.
In this architecture, there is one big database called the container
database (CDB). You can think of it as the root database.
Inside the container database, there are pluggable databases
(PDBs).
There must be at least one pluggable database inside the
container database.
Each pluggable database has the full attributes of a regular
database, including its own users, objects, tables, applications,
etc.
The container database is different; it doesn't have any objects
like the pluggable databases do.
Need?
The primary reasons mentioned for this change were related to addressing
limitations and inefficiencies in previous versions:
In 11g and earlier versions, each database had to be installed on a
separate server3. This was inefficient, especially for smaller databases
used for specific jobs, as dedicating an entire server for such a database was
often unnecessary.
Managing each server was "a lot of work for the DBAs"
Command
Example Commands In PL/SQL? Notes
Type
SELECT INTO, INSERT, SELECT must
DML ✅ Yes
UPDATE use INTO
CREATE, DROP, ALTER, ⚠️Only via EXECUTE
DDL
TRUNCATE IMMEDIATE
Transaction COMMIT, ROLLBACK,
✅ Yes Supported
Control SAVEPOINT
Session ALTER SESSION, SET Not supported in
❌ No
Control ROLE PL/SQL