0% found this document useful (0 votes)
17 views2 pages

PL-SQL Package

The document explains the components of an Oracle package, which includes a specification and a body. The specification declares accessible types, variables, constants, and subprograms, while the body defines these objects and can include private declarations. It also provides simplified syntax for creating both package specifications and bodies, along with an example of a package and its body implementation.

Uploaded by

patelsoham.797
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)
17 views2 pages

PL-SQL Package

The document explains the components of an Oracle package, which includes a specification and a body. The specification declares accessible types, variables, constants, and subprograms, while the body defines these objects and can include private declarations. It also provides simplified syntax for creating both package specifications and bodies, along with an example of a package and its body implementation.

Uploaded by

patelsoham.797
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/ 2

Unit-3 (Stored procedures and User defined functions)

 Package
 Components of an oracle package
 A PACKAGE HAS USUALLY TWO COMPONENTS, A specification AND A body.
 A PACKAGE'S specification DECLARES THE TYPES (VARIABLES OF THE record TYPE), MEMORY
VARIABLES, CONSTANTS, EXCEPTIONS, CURSORS, AND SUBPROGRAMS THAT ARE AVAILABLE FOR
USE.
 A PACKAGE'S BODY FULLY DEFINES CURSORS, FUNCTIONS, AND PROCEDURES AND THUS
IMPLEMENTS THE SPECIFICATION
 Package specification
 THE PACKAGE SPECIFICATION CONTAINS:
 NAME OF THE PACKAGE
 NAMES OF THE DATA TYPES OF ANY ARGUMENTS
 THIS DECLARATION IS LOCAL TO THE DATABASE AND GLOBAL TO THE PACKAGE
 THIS MEANS THAT PROCEDURES, FUNCTIONS, VARIABLES, CONSTANTS, CURSORS AND EXCEPTIONS
AND OTHER OBJECTS, DECLARED IN A PACKAGE ARE ACCESSIBLE FROM ANYWHERE IN THE PACKAGE.
 THEREFORE, ALL THE INFORMATION A PACKAGE NEEDS, TO EXECUTE A STORED SUBPROGRAM, IS
CONTAINED IN THE PACKAGE SPECIFICATIONS ITSELF.
 The simplified syntax for the create package statement is as follows:
Create [or replace] package package_name
{is | as}
Package_specification
End package_name;
 The package body
 THE BODY OF A PACKAGE CONTAINS THE DEFINITION OF PUBLIC OBJECTS THAT ARE DECLARED IN THE
SPECIFICATION.
 THE BODY CAN ALSO CONTAIN OTHER OBJECT DECLARATIONS THAT ARE PRIVATE TO THE PACKAGE.
 THE OBJECTS DECLARED PRIVATELY IN THE PACKAGE BODY ARE NOT ACCESSIBLE TO OTHER OBJECTS
OUTSIDE THE PACKAGE.
 UNLIKE PACKAGE SPECIFICATION, THE package body CAN CONTAIN subprogram bodies.
 AFTER THE PACKAGE IS WRITTEN, DEBUGGED, COMPILED AND STORED IN THE DATABASE
APPLICATIONS CAN REFERENCE THE PACKAGE'S TYPES, CALL ITS SUBPROGRAMS, USE ITS CURSORS,
OR RAISE ITS EXCEPTIONS.
 The simplified syntax for the create package body statement is as follows:
Create [or replace] package body package_name
{is | as}
Package_body
End package_name;
 EXAMPLE PACKAGE SPECIFICATION AND PACKAGE BODY
 Sql> create or replace package pkg1
2 as
3 function area (rad number) return number;
4 procedure print (str1 varchar2 :='hello',
5 str2 varchar2 :='world',
6 end varchar2 :='!' );
7 end;
8 /
 Package created.
 Sql> create or replace package body pkg1
2 as
3 function area (rad number)return number
4 is
5 pi number:=3.14;
6 begin
7 return pi * (rad ** 2);
8 end;
9
10 procedure print(str1 varchar2 :='hello',
11 str2 varchar2 :='world',
12 end varchar2 :='!' )
13 is
14 begin
15 dbms_output.put_line(str1||','||str2||end);
16 end;
17 end;
18 /
 Package body created.

You might also like