0% found this document useful (0 votes)
3 views14 pages

Understanding PL/SQL Packages

PL/SQL packages are schema objects that group procedures, functions, variables, and types, providing advantages such as modularity, encapsulation, and maintainability. A package consists of a specification that declares public components and a body that contains the implementation. They are widely used in PL/SQL to improve structure by separating interface and implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Understanding PL/SQL Packages

PL/SQL packages are schema objects that group procedures, functions, variables, and types, providing advantages such as modularity, encapsulation, and maintainability. A package consists of a specification that declares public components and a body that contains the implementation. They are widely used in PL/SQL to improve structure by separating interface and implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

PL/SQL Packages

• Chapter 9
• Introduction
What is a Package?
• A package is a schema object that groups
• procedures, functions, variables, and types.
Advantages of Packages
• Modularity
• Encapsulation
• Performance
• Security
• Maintainability
Package Specification
• Declares public components
• Acts as interface
• Contains variables, types, procedures,
functions
Package Specification – Example
• CREATE OR REPLACE PACKAGE pkg_name IS
• PROCEDURE p1;
• FUNCTION f1 RETURN NUMBER;
• END;
Package Body
• Contains implementation
• Defines logic
• Can have private components
Package Body – Example
• CREATE OR REPLACE PACKAGE BODY
pkg_name IS
• PROCEDURE p1 IS BEGIN NULL; END;
• FUNCTION f1 RETURN NUMBER IS BEGIN
RETURN 1; END;
• END;
Serially Reusable Packages
• Ensures fresh data per call
• Uses PRAGMA SERIALLY_REUSABLE
Variables in Packages
• Specification variables → Public
• Body variables → Private
Types in Packages
• Record types
• Collections
• Cursors
• Reference cursors
Functions & Procedures
• Declared in spec
• Implemented in body
• Support overloading
Definer vs Invoker Rights
• AUTHID DEFINER (default)
• AUTHID CURRENT_USER
Managing Packages
• USER_OBJECTS
• USER_SOURCE
• USER_DEPENDENCIES
Summary
• Packages improve structure
• Separate interface & implementation
• Widely used in PL/SQL

You might also like