Subprogram is said to be a program unit or module which performs a particular task. And these subprograms are combined together to form a larger program. It is basically called as Modular design. These subprograms can be invoked by another subprogram or the program which is said to be a calling program.
These subprograms can be created by –
- At the schema level – At this level a subprogram is said to be a standalone program that is created with CREATE PROCEDURE OR CREATE FUNCTION statement. This is then stored in the database and can also be deleted by statements DROP PROCEDURE or DROP FUNCTION.
- Inside a package – The program created inside the package is said to be known as packaged subprogram. This is also stored in the database and can be deleted only when the package is deleted with the statement DROP PACKAGE.
- Inside a PL/SQL block – These blocks are said to be as PL/SQL blocks that can also be invoked with the set of parameters. This provides two types of subprograms
Functions – Functions returns a single value, and it is mainly used for computing and returning a value.
Procedures – Procedures do not return a value directly, and these are mainly used for performing an action.