DBMS - PL/SQL
Introduction
PL/SQL stands for Procedural Language/Structured Query Language, which is provided by Oracle as a procedural extension to SQL. SQL is a declara- tive language. In SQL, the statements have no control to the program and can be executed in any order. PL/SQL, on the other hand, is a procedural language that makes up for all the missing elements in SQL. PL/SQL arose from the desire of programmers to have a language structure that was more familiar than SQL’s purely declarative nature.
Structure of PL/SQL
PL/SQL is a 4GL (fourth generation) programming language. It offers all fea-tures 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 over heads. With PL/SQL, one can use the SQL statements together with the control structures (like if ...then) for data manipulation. Besides this, user can define his/her own error messages to display. Thus we can say that PL/SQL combines the data manipulation power of SQL with data processing power of procedural language.
PL/SQL is a block structured language. This means a PL/SQL program is made up of blocks, where block is a smallest piece of PL/SQL code having logically related statements and declarations. A block consists of three sections namely:
Declare, Begin, and Exception followed by an End statement.
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.
Click here PL/SQL NOTES WITH EXAMPLES

Comments