Professional Documents
Culture Documents
Introduction To PL/SQL
Introduction To PL/SQL
Introduction to PL/SQL
PL/SQL:
• Stands for Procedural Language extension to SQL
• Is Oracle Corporation’s standard data access
language for relational databases
• Seamlessly integrates procedural constructs with
SQL
PL/SQL:
• Provides a block structure for executable units of
code. Maintenance of code is made easier with
such a well-defined structure.
• Provides procedural constructs such as:
– Variables, constants, and types
– Control structures such as conditional statements
and loops
– Reusable program units that are written once and
executed many times
PL/SQL Engine
procedural Procedural
PL/SQL Statement
Block Executor
SQL
SQL Statement
Executor
SQL 1
SQL 2
…
SQL
IF...THEN
SQL
ELSE
SQL
END IF;
SQL
DECLARE (Optional)
Variables, cursors, user-defined exceptions
BEGIN (Mandatory)
- SQL statements
- PL/SQL statements
EXCEPTION (Optional)
Actions to perform
when errors occur
END; (Mandatory)
Anonymous Procedure
Function
[DECLARE] PROCEDURE name FUNCTION name
IS RETURN datatype
IS
BEGIN BEGIN BEGIN
--statements --statements --statements
RETURN value;
[EXCEPTION] [EXCEPTION] [EXCEPTION]
Database Server
Tools Constructs
Constructs
Anonymous blocks Anonymous blocks
Application procedures Stored procedures or
or functions functions
Application packages Stored packages
iSQL*Plus
SET SERVEROUTPUT ON
…
DBMS_OUTPUT.PUT_LINE(' The First Name of the
Employee is ' || f_name);
…