Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

PL SQL GUIDLINES.pptx

Uploaded by

jjqgarcia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PL SQL GUIDLINES.pptx

Uploaded by

jjqgarcia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

PL SQL GUIDELINES

ICSC0413 – DATABASE MANAGEMENT SYSTEM


A.Y. 2024 – 2025
INSTRUCTOR: KHRIS VILLEGAS
INTRODUCTION

• It involves discussion about PL/SQL environment, syntax and


guidelines as well as on writing PL/SQL blocks.
WHAT IS PL/SQL ?

• Stands for Procedural Language extensions to the Structured Query


Language (SQL)

• It is used by the Oracle as an extension to SQL which integrates the


structure of procedural language in database programming. It is
usually used as a tool in transaction processing wherein data
manipulation statements are written in a block-oriented structure.

• PL/SQL. It is mostly used by DBA to increase performance in query


processing.
PL/SQL BLOCK STRUCTURE

• PL/SQL program units organize the code into blocks


• A block without a name is known as an anonymous block
• The anonymous block is the simplest unit of PL/SQL
• An anonymous block is an only one-time use and useful in certain
situations such as creating test units.
PL/SQL BLOCK STRUCTURE
SYNTAX
[DECLARE]
Declaration statements;
BEGIN
Execution statements;
[EXCEPTION]
Exception handling statements;
END;
/
PL/SQL BLOCK STRUCTURE

DECLARE
Declaration statements;

• Is an optional section and starts with DECLARE keyword.


• This allows you to define data types, structures, variables, constants,
records and cursor etc.
PL/SQL BLOCK STRUCTURE
PL/SQL BLOCK STRUCTURE
PL/SQL BLOCK STRUCTURE
Guidelines in Declaring Variables
When declaring variables, take note of the following:
1. Declare variables only in the DECLARATION section.
2. Declare one identifier per line.
3. Variables tagged as CONSTANT or NOT NULL must be initialized.
4. Assign values to identifiers using the assignment operator (:=) or the keyword DEFAULT.
5. Storing and Date data types are enclosed in single quotations.
6. BOOLEAN data types can be assigned the values TRUE, FALSE, and NOT NULL.
7. Follow naming conventions for readability.
PL/SQL BLOCK STRUCTURE

• HOST (BIND) VARIABLES


• Host variables are declared outside the PL/SQL block. They are used
to pass runtime values from a PL/SQL variable to the Oracle Server.
Once declared, they can be referenced anywhere within the host
environment. To declare a host variable, the keyword VARIABLE is
used.
PL/SQL BLOCK STRUCTURE

[EXECUTION]
BEGIN
Execution statements;
END;

• EXECUTION section starts with BEGIN keyword and ends with END
• It is used to write the program logic code.
• It is written using DML commands.
PL/SQL BLOCK STRUCTURE

[EXCEPTION]
Exception handling statements;

• It starts with the EXCEPTION keyword.


• It is use to handle the exceptions that occurred in execution section.
• It is also an optional section.
PL/SQL BLOCK STRUCTURE

• Every PL/SQL statement will be followed by semicolon (;)


• PL/SQL engine can process the multiple SQL statements
simultaneously as a single block hence reduce network traffic and
provides better performance.
PL/SQL BLOCK STRUCTURE

• Single forward slash (/), is a signal to instruct SQL*PLUS (SQL Plus)


to execute the PL/SQL block.
Displaying Output from PL/SQL Block

• The output of a PL/SQL Block can be displayed using the


DBMS_OUTPUT.PUT_LINE commands
PL/SQL BLOCK STRUCTURE

• Example
PL/SQL BLOCK STRUCTURE

• Example
PL/SQL BLOCK STRUCTURE

• Example
PL/SQL BLOCK STRUCTURE

• Example
PL/SQL BLOCK STRUCTURE

• Example
PL/SQL BLOCK STRUCTURE

• Example
PL/SQL BLOCK STRUCTURE

• Example
DML STATEMENTS IN PL/SQL

DML statements are used to manipulate data in the database.


Commands include INSERT, UPDATE and DELETE.
REFERENCES
• PL/SQL Tutorial. Retrieved from http://www.plsqltutorial.com
• Oracle / PLSQL. Retrieved from http://www.techonthenet.com
QUESTIONS ?
THANK YOU ☺

You might also like