The PL/SQL stands for Procedural Language extensions to Structured Query Language. Basically, SQL is used to perform basic operations of creating a database, storing data in the database, updating data in the database, retrieving the stored data of database, etc, whereas PL/SQL is a fully Structured Procedural language which enables the developer to combine the powers of SQL with its procedural statements.
Following are some useful features of PL/SQL:
PL/SQL applications can be executed with all types of operating system where we have oracle installed.
All sorts of calculations can be efficiently performed by PL/SQL without the use of oracle engine. This improves transaction performance.
PL/SQL allows error-checking and displays user-friendly messages when error occurs.
PL/SQL supports execution of SQL statements along with the functionality of variable declaration, conditional statements, looping and branching, procedures, functions and triggers.
PL/SQL code is capable of handling exceptions that can affect the flow of program, hence helps in making the code more reliable.
With the above features present in PL/SQL, the utility of PL/SQL programming can be seen in real life projects using databases. As it is capable of performing various logical operations on the database which cannot be executed using simple SQL queries.
For example, conside we have a School Management System database and we want to see the list of students who took admission in last 5 years in school and the fees deposited by them. And at the same time we want to add the total amount of salary money given to the teaching and non-teaching staff. We cannot fetch these records by just executing SQL queries, we might be able to gather the data but it would require multiple SQL queries.
On the other hand if we use PL/SQL, we can write procedures or methods in PL/SQL program to execute complex logic on a database. Another advantage is that we can also detect errors easily as it displays user-friendly messages and it even supports exception handling.
PL/SQL architecture consist of following three components, displayed in the diagram below:
Let's understand what these 3 components are,
PL/SQL block creates the structured logical blocks of code that describes the process to be executed. Such a block consists of SQL statements and PL/SQL instructions that are then passed to the oracle engine for execution. We will learn about this in details in the next tutorial.
The PL/SQL block containing the procedural statements are executed by the PL/SQL statement executor inside the PL/SQL engine. In simpler words, the PL/SQL engine provides the environment in which the PL/SQL block is executed.
Last but not least, comes the Database Server. This can be Oracle DB server or MySQL DB server. The DB server stores data in tables.
Below we have a simple pictorial representation of the 3 components: