Friday, 25 May 2012

What is a subprogram? What are its advantages? | PL SQL

 A named Procedural Language/Structured Query Language (PL/SQL) block is called a subprogram. It has three sections: Declarative, Executable, and Exception Handling (optional).
The main advantage of a subprogram is that it can be compiled and stored in a database.
In addition, it has the following advantages:
a.    Modularization — Refers to a property, which allows you to break the large programs into smaller modules and make the program easy to write and debug.
b.    Easy maintenance — Refers to a property, which allows you to make the modifications in a code because the code is modular and written in one place.
c.    Reusability— Refers to a property, which allows you to reuse the same subprogram within any application. The code of the subprogram need not be re-written each time.
d.    Data integrity and security — Refers to a property, which prevents unauthorized users from accessing the subprogram without the proper rights.
e.    Better performance — Helps in avoiding repeated parsing on subsequent calls to the same subprogram as the code is compiled, parsed, and available in the shared Structured Query Language (SQL) area. This reduces the number of calls to the database; and therefore, increases the network performance.
 An anonymous block has no specification or header section. It only consists of a PL/SQL block in the body that contains the declaration, executable, and exception sections.