PL/SQL
PL/SQL, which stands for Procedural Language extensions to
the Structured Query Language (SQL).
It is a combination of SQL along with the procedural features of
programming languages.
It was developed by Oracle Corporation in the early 90's to enhance
the capabilities of SQL.
PL/SQL is one of three key programming languages embedded in
the Oracle Database, along with SQL itself and Java.
The purpose of PL/SQL is to merge database commands with
procedural programming language.
Features of PL/SQL
PL/SQL is tightly integrated with SQL.
It offers extensive extensive error checking mechanisms.
It supports numerous data types for flexible data handling.
Includes a variety of programming structures, such
as loops and conditionals.
It supports structured programming through functions and
procedures.
It supports object-oriented programming, enabling more
complex data handling and manipulation.
It supports the web application development and server
pages.
PL/SQL provides a built-in, interpreted and OS independent
programming environment.
PL/SQL's general syntax is based on that of ADA and Pascal
programming language.
Apart from Oracle, PL/SQL is available in TimesTen in-memory
database and IBM DB2.
PL/SQL Block Structured
Declarations: This section, starting with the keyword DECLARE, is
optional and used for defining variables, cursors, subprograms, and
other elements required within the block.
Executable Commands: Enclosed between the keywords BEGIN
and END, this mandatory section contains executable PL/SQL
statements. It must include at least one executable line of code,
even if it's just a NULL command indicating no action.
Exception Handling: This starts with the keyword EXCEPTION, this
optional section deals with handling errors in the program through
defined exceptions.
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling>
END;
PL/SQL statements are terminated with a semicolon(;).
Additionally, blocks can be nested within each other using BEGIN
and END keywords
The PL/SQL Delimiters
Delimiter Description
Addition, subtraction/negation,
+, -, *, /
multiplication, division
% Attribute indicator
' Character string delimiter
. Component selector
(,) Expression or list delimiter
: Host variable indicator
, Item separator
" Quoted identifier delimiter
= Relational operator
@ Remote access indicator
; Statement terminator
:= Assignment operator
=> Association operator
|| Concatenation operator
** Exponentiation operator
<<, >> Label delimiter (begin and end)
Multi-line comment delimiter (begin
/*, */
and end)
-- Single-line comment indicator
.. Range operator
<, >, <=, >= Relational operators
<>, '=, ~=, ^= Different versions of NOT EQUAL