6) Subprograms: 6.1) Procedures
6) Subprograms: 6.1) Procedures
6)Subprograms
Subprograms are the named PL/SQL blocks that can take parameters and can be invoked from the calling environment. Types Of Subprograms: Procedures. Functions.
6.2)Functions: A Function is a subprogram that returns a value. The value returned can be
simple data type or complex. A Function has header, declarative part, an executable part. LOCAL: Local function is not stored in a database but used within a program. STORED:Stored function is stored in a database. 6.2.1)PL/SQL Program to implement Local Functions.
7. Introduction to Packages
Packages.
PL/SQL package is a group of related stored functions, procedures, types, cursors and etc. PL/SQL package is like a library once written stored in the Oracle database and can be used by many applications. A package has two parts: a. A package specification is the public interface of your applications. The public here means the stored function, procedures, type are accessible by other applications. b. A package body contains the code that implements the package specification.
Syntax.
CREATE [OR REPLACE] PACKAGE package_name IS [definitions of public TYPES ,declarations of public variables, types, and objects ,declarations of exceptions ,pragmas ,declarations of cursors, procedures, and functions ,headers of procedures and functions] END [package_name];
Syntax.
CREATE [OR REPLACE] PACKAGE BODY [schema.]package_name AS plsql_package_body
8. Introduction to Triggers
A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database. For example, when a new record (representing a new worker) is added to the employees table, new records should also be created in the tables of the taxes, vacations and salaries.
Syntax.
{CREATE| REPLACE}TRIGGER trigger_name {BEFORE| AFTER} {INSERT[ORUPDATE][ORDELETE]} ON table_name [FOR EACH ROW] [DECLARE...] BEGIN ..... END 8.1) PL/SQL program to implement triggers.