PPT of Chapter 3.1 -Package, Procedures and Triggers
PPT of Chapter 3.1 -Package, Procedures and Triggers
ENGINEERING
• The main DBMS course, we learn about the structural formation of data, maintain data
integrity, multitasking with concurrent access and recovery without occurring crashes,
data structures, data models etc. and their working in which every organization is based.
• At the end of the course, the students may understand the concepts of data structures,
data models and design, construction of queries by using SQL, uses and applications of
database design etc
COURSE OUTCOMES
1. To have good understanding of database system concepts and design databases for
different applications.
2. To learn how to use a DBMS and RDBMS.
3. To implement and understand different types of DDL, DML and DCL statements.
4. To understand transaction concepts related to databases and recovery/backup
techniques required for the proper storage of data.
Topics covered
Package
Procedures, Functions, Variables, and other
elements that are grouped for Modularity and
Reusability.
Package
Key Benefits of Using PL/SQL Packages
Package Package
Specification Body
Package
1. Package Specification
The package specification declares the public interface of the package. It includes
declarations of procedures, functions, variables, cursors, and other constructs that are
meant to be accessible from outside the package. The specification is like a header file that
defines what a package can do.
Example of Package Specification:
Package
2. Package Body
The package body contains the implementation of the details of the package. It includes the
coding of the procedures or functions which are decalared in the package specification.
The body can also contain private variables and procedures that are not exposed to outside
the code.
Example of Package Body:
Package
Bodiless Package
A bodiless package in PL/SQL refers to a package that does not require a package body. In such
cases, only the package specification is created, and it contains all the declarations of variables,
constants, cursors, or subprograms. However, the package body is omitted because no
implementation is required.
When to Use Bodiless Packages?
1. Public Declarations Only: If the package contains only public variables, constants, or
cursors and does not need any subprogram implementation.
2. Forward Declarations: When subprograms (procedures/functions) are declared but
implemented elsewhere (e.g., standalone procedures or functions).
3. Minimal Complexity: If the package is used as a simple interface to expose global
variables or cursors.
Package
Syntax of a Bodiless Package
Package
Example of a Bodiless Package
Package
Advantages of Bodiless Packages
• Simplified Structure: No need for a body when implementation is not required.
• Improved Readability: Only the interface (specification) is provided, making it easy to
understand.
• Reusability: Useful for sharing global variables, constants, or cursors across multiple
PL/SQL programs.
• Forward Compatibility: You can add a package body later if needed.
1. Procedure Header
• The procedure header includes the procedure name and optional parameter list.
• It is the first part of the procedure and specifies the name and parameters
2. Procedure Body
• The procedure body contains the executable statements that implement the specific
business logic.
• It can include declarative statements, executable statements, and exception-handling
statements
Procedures
Create Procedures in PL/SQL
Syntax
CREATE PROCEDURE syntax is:
Procedures Example
In this example, we will create a procedure in PL/SQL
Procedures
Parameters in Procedures
In PL/SQL, parameters are used to pass values into procedures. There are three types of parameters used in
procedures:
1. IN parameters
Used to pass values into the procedure
Read-only inside the procedure
Can be a variable, literal value, or expression in the calling statement.
2. OUT parameters
Used to return values from the procedure to the calling program
Read-write inside the procedure
Must be a variable in the calling statement to hold the returned value
3. IN OUT parameters
Used for both passing values into and returning values from the procedure
Read-write inside the procedure
Must be a variable in the calling statement
Procedures
Modify Procedures in PL/SQL
To modify an existing procedures in
PL/SQL use the ALTER
PROCEDURE command:
Syntax
Procedures
Example
In this example, we will
modify a procedure in PL/SQL
Procedures
Drop Procedure in PL/SQL
To drop a procedure in PL/SQL use the DROP PROCEDURE command
Syntax:
DROP PROCEDURE procedure_name
Trigger
Key Terms
name: The name of the trigger.
is_instead_of_trigger: Whether the trigger is an INSTEAD OF trigger.
type = ‘TR’: This filters the results to show only triggers .
THANK YOU