Professional Documents
Culture Documents
PL/SQL
Creating Packages
Creating Packages
Objectives
This lesson covers the following objectives:
Describe the reasons for using a package
Describe the two components of a package:
specification and body
Create packages containing related variables, cursors,
constants, exceptions, procedures, and functions
Create a PL/SQL block that invokes a package construct
Creating Packages
Purpose
You have already learned how to create and use
stored procedures and functions.
Suppose you want to create several procedures and/or
functions that are related to each other. An application
can use either all of them or none of them.
Wouldnt it be easier to create and manage all the
subprograms as a single database object: a package?
Creating Packages
Purpose (cont.)
In this lesson, you learn what a package is and what its
components are. You also begin to learn how to create
and use packages.
Creating Packages
Creating Packages
Package
specification
Package
body
Creating Packages
Package
specification
Package
body
Creating Packages
Package
specification
Variable_2
Procedure B definition
Variable_3
Package
body
Creating Packages
Creating Packages
10
Creating Packages
11
Creating Packages
12
Creating Packages
13
Creating Packages
14
Creating Packages
15
Creating Packages
16
Creating Packages
17
Creating Packages
Creating Packages
19
Creating Packages
20
Creating Packages
21
Creating Packages
22
Creating Packages
Describing a Package
You can DESCRIBE a package in the same way as you
can DESCRIBE a table or view:
DESCRIBE check_emp_pkg
Procedure
Argument
In Out
Datatype
CHECK_EMP_PKG
CHK_DEPT_MGR
P_EMPID
IN
NUMBER
P_MGR
IN
NUMBER
P_DATE
IN
DATE
CHK_HIREDATE
Creating Packages
24
Creating Packages
Terminology
Key terms used in this lesson included:
Encapsulation
OR REPLACE
Package body
Package specification
PL/SQL packages
25
Creating Packages
Summary
In this lesson, you should have learned how to:
Describe the reasons for using a package
Describe the two components of a package:
specification and body
Create packages containing related variables, cursors,
constants, exceptions, procedures, and functions
Create a PL/SQL block that invokes a package construct
26