0% found this document useful (0 votes)
119 views17 pages

6.1 PLSQL PPT CH6 PDF

This document provides an overview of PL/SQL packages. It defines what a package is, why they are needed, and package components. A package is an Oracle object that holds other objects like procedures, functions, variables and constants. Packages promote code reuse, improve performance, and enable privilege management. The package specification declares public objects while the package body defines private objects and code. A demonstration shows how a package specification interfaces with a package body to implement stored procedures that interact with a database table.

Uploaded by

phanidhar paluri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views17 pages

6.1 PLSQL PPT CH6 PDF

This document provides an overview of PL/SQL packages. It defines what a package is, why they are needed, and package components. A package is an Oracle object that holds other objects like procedures, functions, variables and constants. Packages promote code reuse, improve performance, and enable privilege management. The package specification declares public objects while the package body defines private objects and code. A demonstration shows how a package specification interfaces with a package body to implement stored procedures that interact with a database table.

Uploaded by

phanidhar paluri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

PL/SQL Tutorial

By (Procedural - Structured Query Language)


Anjali singh

Let’s make coding fun!


Chapter 6
PL/SQL Tutorial
Packages & Demonstration
Let’s make coding fun!
What do we learn in this Chapter?
What is Package?

Why do we need Package?

Package Components

Demonstration

HOMEWORK
What is
Package?
A package is an Oracle object, which holds other
• Generic
• Encapsulated
objects within it. Object commonly help within a
• Re-usable code package are procedure, functions, variables,
• Standalone sub
program
constants, cursors and exceptions.
Why do we need
Package?

1. Granting privileges efficiently


2. Enable overloading procedure and functions
3. Enables organization of commercial applications into efficient
modules. Improve performance by loading multiple objects into
memory at once. Therefore, subsequent calls to related
subprograms in package require no Input/Output
4. Promote code reuse through the use of libraries that contain
stored procedures and function, thereby reducing redundant
coding
Package Components
Package
Package Package
body or
Specification Declaration
definition

PACKAGE

Procedure Functions Cursor

Trigger Variables Constants


Package Components
Package
Package
body or
Specification
definition

The specification is the interface to the package. It


just DECLARES the types, variables, constants, exceptions, cursors,
and subprograms that can be referenced from outside the The package body has the codes for
package. In other words, it contains all information about the various methods declared in the package
content of the package, but excludes the code for the specification and other private
subprograms. declarations, which are hidden from the
All objects placed in the specification are called public objects. Any code outside the package.
subprogram not in the package specification but coded in the
package body is called a private object.
Package Syntax

PACKAGE BODY
CREATE OR REPLACE PACKAGE BODY
PACKAGE SPECIFICATION
<package_name> AS
CREATE PACKAGE <Package_name> AS
PROCEDURE Procedure_name_def IS
<declaration of database object>
BEGIN
PROCEDURE <Procedure_name_Def>;
SQL STATEMENT;
FUNCTION <function_name_Def>;
PL/SQL STATEMENTS;
VARIABLES;
END Procedure_name;
END PACKAGE_NAME;
END Package_name;
Package Demonstration

Package PACKAGE_EXAMPLE
Package
Package Body implementation PROCEDURE ADD_VALUES
Specification
Execution PROCEDURE DELETE_VALUES

TABLEA

COLA COLB
ROW11 10
ROW21 20
Package Demonstration
Package PACKAGE_EXAMPLE
Specification PROCEDURE ADD_VALUES
PROCEDURE DELETE_VALUES

TABLEA

COLA COLB
ROW11 10
ROW21 20
Package Body

PACKAGE_EXAMPLE
PROCEDURE ADD_VALUES
PROCEDURE DELETE_VALUES

TABLEA

COLA COLB
ROW11 10
ROW21 20
Package Body

PACKAGE_EXAMPLE
PROCEDURE ADD_VALUES
PROCEDURE DELETE_VALUES

TABLEA

COLA COLB
ROW11 10
ROW21 20
IMPORTANT FACTS
PL/SQL code outside the package reference objects from within the
package using dot notation , declared in package specification called
PUBLIC

Objects that are declared inside the package body, their use is
restricted to within that package only called PRIVATE

Multiple procedures that are declared with the same name are called
Overloaded Procedures.

Multiple functions that are declared with the same name are called
Overloaded Functions
Practice Project
Online Banking System

Account_No Acct_holder Balance Eligibility


ACCT001 Alex 120000 NO
ACCT002 Mark 340000 YES
ACCT003 John 245000 YES
Instructions
ACCT005 Felix 150000 NO 1. Create a package and define function which helps
to perform update on credit eligibility condition
when balance is more than 220000 for an
account holder

For more resource , assistance and


questions , please contact
[email protected] Let’s make coding fun!
Conclusion

Stored Trigger
PL/SQL Functions
Procedure

Interview &
Package
Cursors Certifications
Demonstration
Tips

Let’s make coding fun!


Let’s make coding fun!

You might also like