Dbms_Unit_I
Dbms_Unit_I
UNIT V
5
PL/SQL
Shortcomings in SQL
We know, SQL is a powerful tool for accessing the database but it suffers from
some deficiencies as follows:
(a) SQL statements can be executed only one at a time. Every time to execute
a SQL statement, a call is made to Oracle engine, thus it results in an
increase in database overheads.
Structure of PL/SQL
PL/SQL is a 4GL (fourth generation) programming language. It offers all features
of advanced programming language such as portability, security, data
encapsulation, information hiding, etc. A PL/SQL program may consist of
more than one SQL statements, while execution of a PL/SQL program makes
only one call to Oracle engine, thus it helps in reducing the database overheads.
With PL/SQL, one can use the SQL statements together with the control
structures (like if . . . then) for data manipulation.
Declare Section
Declare section declares the variables, constants, processes, functions, etc., to
be used in the other parts of program. It is an optional section.
Begin Section
It is the executable section. It consists of a set of SQL and PL/SQL statements,
which is executed when PL/SQL block runs. It is a compulsory section.
Exception Section
This section handles the errors, which occurs during execution of the PL/SQL
block. This section allows the user to define his/her own error messages. This
section executes only when an error occurs. It is an optional section.
End Section
This section indicates the end of PL/SQL block.
Every PL/SQL program must consist of at least one block, which may
consist of any number of nested sub-blocks. Figure 5.1 shows a typical PL/SQL
block.
Character Set
A PL/SQL program consists of text having specific set of characters. Character
set may include the following characters:
– Alphabets, both in upper case [A–Z] and lower case [a–z]
– Numeric digits [0–9]
– Special characters ( ) + − * /< >= ! ∼ ˆ ; : . _ @ % , __ # $ & |
{}?[]
– Blank spaces, tabs, and carriage returns.
PL/SQL is not case sensitive, so lowercase letters are equivalent to corresponding
uppercase letters except within string and character literals.