0% found this document useful (0 votes)
130 views9 pages

PL/SQL: Programming Language For SQL

PL/SQL is an extension of SQL that allows integration of SQL statements with common programming language statements. It allows programmers to create blocks of code and send to the RDBMS as single commands. PL/SQL offers advantages like procedural capabilities, improved performance, enhanced productivity and portability.

Uploaded by

bookworm_shashi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views9 pages

PL/SQL: Programming Language For SQL

PL/SQL is an extension of SQL that allows integration of SQL statements with common programming language statements. It allows programmers to create blocks of code and send to the RDBMS as single commands. PL/SQL offers advantages like procedural capabilities, improved performance, enhanced productivity and portability.

Uploaded by

bookworm_shashi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

PL/SQL

Programming Language
For SQL
PL/SQL Introduction

• PL/SQL is an extension of SQL


• PL/SQL is used in conjunction with data retrieval
(SELECT) and maintenance (INSERT, DELETE, and
UPDATE) commands
• PL/SQL is also used in conjunction with transaction
processing commands(COMMIT, ROLLBACK,
SAVEPOINT,LOCK TABLE)
• PL/SQL is more procedural than SQL LOCK TABLE)
• PL/SQL is more procedural than SQL
PL/SQL Introduction (continued)

• Basic unit of PL/SQL Code: The Block (Begin .. End)


• PL/SQL allows the integration of SQL statements with
common programming language statements.
PL/SQL Statements

• Control Flow Statements
– IF..THEN..ELSE
– EXIT
– GOTO
• Repetition Statements
– FOR..Loop
– WHILE..Loop
• Assignment Statements
• PL/SQL allows programmers to create a block of code 
and send it to the RDBMS as a single command
Advantages Of PL/SQL
• Basic Advantages of Using PL/SQL
– Procedural Capabilities - Can use SQL to
retrieve rows, then process them one at a time.
– Improved Performance - SQL statements must
be processed one at a time (ex. updating several
related tables). PL/SQL allows the grouping of these
commands in a block of code, transmitting the
entire block to ORACLE for execution.
Advantages of PL/SQL (continued)

• Enhanced Productivity - PL/SQL can be used in many


other products: SQL*FORMS, Embedded SQL, etc.
• Portability - PL/SQL can be used only any
hardware or operating system running SQL.
Advantages Of PL/SQL

Integration With The RDBMS - Both ORACLE and PL/SQL


have their foundations in SQL. Datatypes are the same,
so commands from either language can be integrated with
the other.
The %TYPE attribute can be used to declare based on the
data type of an attribute previously defined in the system
catalog.
If the datatype changes in the catalog, the
variable definition changes automatically in the PL/SQL
variable.
An Example PL/SQL Block

-- This is a sample block to process buying a


-- golf club. If we have a Big Bertha
-- driver in stock decrease inventory by one
-- and record the purchase and the current
-- date/time. If not, insert a message in the
-- TEMP table along with the current date/time
--
DECLARE
num-in-stock NUMBER(5);
BEGIN
SELECT quantity
INTO num_in_stock
FROM inventory_table
WHERE product = ‘Big Bertha driver’;
An Example PL/SQL Block (continued)
-- Make sure there are enough drivers in
-- stock
--
IF num_in_stock > 0
THEN
UPDATE inventory-table
SET quantity = quantity - 1
WHERE product = ‘Big Bertha driver’;
INSERT INTO purchase_record VALUES
(‘BB driver PURCHASED’, SYSDATE);
ELSE
INSERT INTO purchase_record VALUES
(‘OUT OF BB drivers’, SYSDATE);
END IF;
COMMIT;
END;

You might also like