PL 1 - Basics
PL 1 - Basics
CONTENTS:
PL/SQL BASICS
A N O N Y M O U S B LO
CKS CONTROL ST
RUCTURES
02/19/2025
Session
Outcomes
At the end of this session, you will be able
to:
● Understand the PL/SQL Block
terminology and features of PL/SQL
● Use various PL/SQL types, variables and
subtypes
● Use SQL statements inside PL/SQL Block
● Use various PL/SQL control structures
● Write and execute anonymous Blocks
02/19/2025 2
SQ
L
● The purpose of SQL is to provide an
interface to a relational database such as
Oracle Database, and all SQL statements
are instructions to the database.
02/19/2025 3
Why
PLSQL
If SQL is so
powerful,
why we
require to
use
PL/SQL?
Let us think
about few
scenarios…
02/19/2025 4
Why
PLSQL
How can we have a chain of SQL statements which
produce result according to the output of previous
queries?
02/19/2025 5
Introducti
on
• The PL/SQL programming language was
developed by Oracle Corporation in the late
1980s as procedural extension language for
SQL and the Oracle relational database.
02/19/2025 6
Why
PL/SQL?
• The purpose of PL/SQL is to combine
database language and procedural
programming language.
02/19/2025 8
Why
PL/SQL? Tight
Integration
with SQL
Access to
Better
Pre-defined
Performance
Packages
Supports
both
Tight Security
static and
Advantages dynamic
SQL.
Of
PL/SQL
Support for
Object- Higher
Oriented Productivity
Programming
Support for
Developing
Full Portability
Web
Applications
02/19/2025
PL/SQL
Block
• PL/SQL is a block-structured language.
• Each program written in PL/SQL is written as a
block.
• Blocks can also be nested.
• Each block is meant for a particular task.
PL/SQL
Block types
Anonymous Name
Block d
Block
02/19/2025
PL/SQL
Block
02/19/2025
PL/SQL Anonymous
Block
02/19/2025
Comments in
PL/SQL
02/19/2025
First PL/SQL
Block
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Hello! Welcome to PL/SQL’);
END;
02/19/2025
PL/SQL Control
Structures
● PL/SQL, like other 3GL has a variety of control
structures which include
• Conditional controls
o IF
• Iterative Controls (Loops)
o Simple loop
o While loop
o For loop
• Sequential control
o GOTO
02/19/2025
Conditional controls
IF
● Syntax
IF condition 1 THEN
-- Executes when the condition 1 is true
Statements;
ELSIF condition 2 THEN
-- Executes when the condition 2 is true
Statements;
ELSIF condition3 THEN
-- Executes when the condition 3 is true
Statements;
ELSE
-- executes when the none of the above
condition is true
Statements;
END IF;
02/19/2025
Example: IF .. ELSE ..
END IF
Declare
mroll
number(10);
matt
number(10);
Begin
mroll:= &mroll;
select at into matt from stud11 where
roll = mroll; if matt<75 then
dbms_output.put_line(mroll||'is
detained'); update stud11 set
status='D' where roll=mroll; else
dbms_output.put_line(mroll||'is Not
detained'); update stud11 set
status='ND'where roll=mroll;
02/19/2025 end if;
End;
Thank
You
02/19/2025