0% found this document useful (0 votes)
74 views8 pages

6) Subprograms: 6.1) Procedures

The document discusses various PL/SQL programming concepts used in relational database management systems including subprograms like procedures and functions, packages, and triggers. Procedures perform actions while functions return values. Packages group related objects and provide public and private interfaces. Triggers are code that automatically executes in response to events on tables or views and are used to maintain data integrity.

Uploaded by

Rachit Chauhan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views8 pages

6) Subprograms: 6.1) Procedures

The document discusses various PL/SQL programming concepts used in relational database management systems including subprograms like procedures and functions, packages, and triggers. Procedures perform actions while functions return values. Packages group related objects and provide public and private interfaces. Triggers are code that automatically executes in response to events on tables or views and are used to maintain data integrity.

Uploaded by

Rachit Chauhan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Relational Database Management System

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.1)Procedures: A Procedure is a subprogram that performs one or more actions. Procedures


are key building blocks of a modular code, allowing you to both consolidate and reuse your program logic. LOCAL: Local procedure is not stored in a database but used within a program. STORED:Stored procedure is a procedure stored in a database (e.g., If a procedure is stored in a database, it becomes like a library function). Local Procedure: In: This mode when specified is used to pass a constant value from the calling environment (sql*plus)into the procedure. It is Default Mode. Out: This mode when specified passes a value from the procdure to the calling environment. InOut: This mode when specified, passes a value from the calling environment into the procedure and possibly a different value from the procedure back to the calling environment using the same parameter. 6.1.1): PL/SQL Program to implement Local Procedure.

Relational Database Management System

6.1.2) PL/SQL Program to implement Local Procedure.

STORED PROCEDURES: 6.1.3)PL/SQL Program to implement Stored Procedure.

Relational Database Management System

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.

6.2.2): PL/SQL Program to implement Stored Functions.

Relational Database Management System

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.

Creating PL/SQL Package Specification.


The package specification is required when you create a new package. The package specification lists all the objects which are publicly accessible from other applications. The package specification also provides the information that developers need to know in order to use the interface. In short, package specification is the packages API. If the package specification does not contain any stored functions, procedures and no private code is needed, you dont need to have a package body. These packages may contai n only type definition and variables declaration. Those variables are known as package data. The scope of package data is global to applications. It is recommended that you should hide as much as package data as possible and use get and set functions to read and write that data. By doing this, you can prevent your package data changed unintentionally.

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];

Creating PL/SQL Package Body.


PL/SQL package body contains all the code that implements stored functions, procedures and cursors listed in the package specification.

Relational Database Management System

Syntax.
CREATE [OR REPLACE] PACKAGE BODY [schema.]package_name AS plsql_package_body

7.1)PL/SQL program to implement packages.

Relational Database Management System

Relational Database Management System

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.

8.2)PL/SQL program to Enable or Disable triggers.

Relational Database Management System 8.3) PL/SQL program to Drop trigger.

You might also like