0% found this document useful (0 votes)
13 views18 pages

PL 1 - Basics

This document provides an overview of PL/SQL, including its basics, control structures, and the significance of using PL/SQL alongside SQL for database programming. It outlines the features of PL/SQL, such as block structure, error handling, and the ability to execute SQL statements within PL/SQL blocks. Additionally, it explains the differences between anonymous and named blocks, as well as various control structures like conditional and iterative controls.

Uploaded by

attarriaan6226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views18 pages

PL 1 - Basics

This document provides an overview of PL/SQL, including its basics, control structures, and the significance of using PL/SQL alongside SQL for database programming. It outlines the features of PL/SQL, such as block structure, error handling, and the ability to execute SQL statements within PL/SQL blocks. Additionally, it explains the differences between anonymous and named blocks, as well as various control structures like conditional and iterative controls.

Uploaded by

attarriaan6226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

PL/SQL

CONTENTS:
PL/SQL BASICS
A N O N Y M O U S B LO
CKS CONTROL ST
RUCTURES

Dr. Yogita Pagar (Bhise)

DEPARTMENT OF COMPUTER ENGINEERING


K.K.W.I.E.E.R., Nashik

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.

● The strengths of SQL provide benefits for all


types of users, including application
programmers, database administrators,
managers, and end users.

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?

How can we take any smart decisions based on users


input or based on output on previous queries..?

How can we automate any task using SQL?

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.

• PL/SQL, supplement SQL with standard


programming- language features like:
• Block (modular) structure
• Flow-control statements and loops
• Variables, constants, and types
• Structured data
• Customized error handling

02/19/2025 6
Why
PL/SQL?
• The purpose of PL/SQL is to combine
database language and procedural
programming language.

• By extending SQL, PL/SQL offers a unique


combination of power and ease of use.

• PL/SQL fully supports all SQL data


manipulation statements.

• We can write procedures and functions which


can be invoked from different applications.
02/19/2025 7
Why
PL/SQL?
● provides facilities like condition checking,
branching, looping.
● Entire block of SQL statements to engine
reduces network traffic
● Permits dealing with errors
● Use of variables

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

Anonymous Block Named Block

□Anonymous block doesn’t □Named block do have


have name. names.

□After compilation, it is not □Once compiled, Named


getting stored on oracle blocks are getting
server. stored on oracle server.

□We can not call □We can call them in


anonymous block in any ay other pl/sql block
other pl/sql block

02/19/2025
PL/SQL Anonymous
Block

02/19/2025
Comments in
PL/SQL

• To comment line or lines in a PL/SQL


program use,

• -- for single line comment

• /* */ for multi-line comment

02/19/2025
First PL/SQL
Block
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Hello! Welcome to PL/SQL’);
END;

• DBMS_OUTPUT is a package which is used for


debugging, or for displaying messages SQL*Plus

• PUT_LINE is a procedure within that package; it


accepts a line of information as input

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

You might also like