0% found this document useful (0 votes)
77 views

PL-SQL: Unit 5

PL/SQL is a procedural language extension of SQL. It allows programmers to write code in a procedural format and combines the data manipulation power of SQL with the processing power of procedural languages. The PL/SQL architecture consists of PL/SQL blocks that contain code, a PL/SQL engine that processes the code, and a database server that stores data and executes SQL. PL/SQL supports various programming constructs like variables, conditions, loops, functions and procedures to manipulate data in the database server.

Uploaded by

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

PL-SQL: Unit 5

PL/SQL is a procedural language extension of SQL. It allows programmers to write code in a procedural format and combines the data manipulation power of SQL with the processing power of procedural languages. The PL/SQL architecture consists of PL/SQL blocks that contain code, a PL/SQL engine that processes the code, and a database server that stores data and executes SQL. PL/SQL supports various programming constructs like variables, conditions, loops, functions and procedures to manipulate data in the database server.

Uploaded by

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

PL-SQL

Unit 5
PL/SQL
PL SQL basically stands for "Procedural Language extensions to SQL". This is the
extension of

Structured Query Language (SQL) that is used in Oracle. Unlike SQL, PL/SQL
allows the

programmer to write code in procedural format.

It combines the data manipulation power of SQL with the processing power of
procedural

language to create a super powerful SQL queries.


It allows the programmers to instruct the compiler 'what to do' through SQL and 'how to
do'

through its procedural way.

Similar to other database languages, it gives more control to the programmers by the
use of

loops, conditions and object oriented concepts.


Architecture of PL/SQL
The PL/SQL architecture mainly consists of following 3 components:
1. PL/SQL block
2. PL/SQL Engine
3. Database Server
PL/SQL block:
This is the component which has the actual PL/SQL code.
This consists of different sections to divide the code logically (declarative section for
declaring purpose, execution section for processing statements, exception handling
section for handling errors)
It also contains the SQL instruction that used to interact with the database server.
All the PL/SQL units are treated as PL/SQL blocks, and this is the starting stage of the
architecture which serves as the primary input.
Following are the different type of PL/SQL units.
o Anonymous Block
o Function
o Library
o Procedure
o Package Body
o Package Specification
o Trigger
o Type
o Type Body
PL/SQL Engine
PL/SQL engine is the component where the actual processing of the
codes takes place.
PL/SQL engine separates PL/SQL units and SQL part in the input
The separated PL/SQL units will be handled with the PL/SQL engine itself.
The SQL part will be sent to database server where the actual interaction
with database
takes place.
It can be installed in both database server and in the application server.
Database Server:
This is the most important component of Pl/SQL unit which stores the
data.
The PL/SQL engine uses the SQL from PL/SQL units to interact with
the database
server.
It consists of SQL executor which actually parses the input SQL
statements and execute
the same.
Below is the pictorial representation of Architecture of PL/SQL.
What is Identifiers?
Identifiers are nothing but a name that is given to a PL/SQL object. The object
could be constant, variable, exception, cursors, procedures, function, package,
trigger, object type, reserve word or label.

Properties of Identifiers

● Must start with a letter


● Maximum size is limited to 30 letters
● Cannot contain whitespace characters
● Can contain dollar sign ('$'), underscore ('_') and hash sign ('#')
● Is case-insensitive
Variable Declaration in PL/SQL
PL/SQL variables must be declared in the declaration section or in a
package as a global variable. When you declare a variable, PL/SQL
allocates memory for the variable's value and the storage location is
identified by the variable name.
The syntax for declaring a variable is −
variable_name [CONSTANT] datatype [NOT NULL] [:= |
DEFAULT initial_value]
operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulation. PL/SQL language is rich in
built-in operators and provides the following types of operators −
● Arithmetic operators
● Relational operators
● Comparison operators
● Logical operators
● String operators
Arithmetic Operators
Following table shows all the arithmetic operators supported by PL/SQL. Let
us assume variable A holds 10 and variable B holds 5, then −

Show Examples

Operator Description Example


+ Adds two operands A + B will give 15
- Subtracts second operand from the first A - B will give 5
* Multiplies both operands A * B will give 50
/ Divides numerator by de-numerator A / B will give 2
** Exponentiation operator, raises one
operand to the power of other A ** B will give 100000
Relational Operators
Relational operators compare two expressions or values and return a Boolean result. Following table shows all the relational
operators supported by PL/SQL. Let us assume variable A holds 10 and variable B holds 20, then −
Comparison Operators
Comparison operators are used for comparing one expression to another. The result is always either TRUE, FALSE or NULL.
Logical Operators
Following table shows the Logical operators supported by PL/SQL. All these operators
work on Boolean operands and produce Boolean results. Let us assume variable A
holds true and variable B holds false, then −
PL/SQL Operator Precedence
The Loop Control Statements
Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects
that were created in that scope are destroyed.
PL/SQL supports the following control statements. Labeling loops also help in taking the control outside a loop. Click the
following links to check their details.
What is Cursor?
Cursor is the work area which Oracle reserves for internal processing of
SQL statements.
This work area is private for oracles reserved are called cursor.
Cursor area also saying session cursor. because session cursor store
information until the session end.
Both way you can manage session cursor either implicit cursor or explicit
cursor.
Using procedural statement you can get any information using session
attribute

You might also like