Package body, PL-SQL Programming

The Package Body

The package specification is implemented by the package body. That is, the package body has the definition of every cursor and the subprogram declared in the package specification. Remember that the subprograms defined in the package body are available outside the package only if their specifications also show in the package specification. To match the subprogram specifications and bodies, the PL/SQL does a token-by-token comparison of their headers. Therefore, except for white space, the headers should match word for word. Or else, the PL/SQL raises an exception, as the illustration below shows:

CREATE PACKAGE emp_actions AS

...

PROCEDURE calc_bonus (date_hired emp.hiredate%TYPE, ...);

END emp_actions;

CREATE PACKAGE BODY emp_actions AS

...

PROCEDURE calc_bunus (date_hired DATE, ...) IS

-- parameter declaration raises an exception as 'DATE'

-- does not match 'emp.hiredate%TYPE' word for word

BEGIN ... END;

END emp_actions;

The package body can also contain the private declarations that define the types and items essential for the internal workings of the package. The scopes of these declarations are local to the package body. And hence, the declared types and items are unapproachable except from within the package body. Dissimilar the package specification, the declarative section of a package body can have the subprogram bodies.

The declarative section below of the package body is the optional initialization sections that typically hold the statements that initialize some of the variables formerly declared in the package.

The initialization section of the package plays a minor role as, dissimilar subprograms; the package cannot be called or passed parameters. As an outcome, the initialization section of the package is only run once, that is the first time you reference the package. Keep in mind that, if a package specification declares only constants, types, variables, exceptions, and call specifications, the package body is needless. Though, the body can still be used to initialize the items declared in the package specification.

Posted Date: 10/8/2012 1:08:52 AM | Location : United States







Related Discussions:- Package body, Assignment Help, Ask Question on Package body, Get Answer, Expert's Help, Package body Discussions

Write discussion on Package body
Your posts are moderated
Related Questions
Negation (NOT, ¬) - SQL There are three rows instead of just two. As you can see, ¬ p is defined as in two-valued logic (2VL) when p is either true or false, but ¬ (unknown) i

Using SET TRANSACTION You use the SET TRANSACTION statement to begin the read-only or read-write transaction, start an isolation level, or assign your present transaction to a

Effects of NULL The numeric variable X, perhaps of type INTEGER, might be assigned NULL. In that case the result of evaluating X + 1 is NULL, and so SET Y = X + 1 assigns NULL

Scope and Visibility The References to an identifier are resolved according to its visibility and scope. The scope of an identifier is that area of a program unit (subprogram, b

Using Subqueries A subquery is a query (typically enclosed by parentheses) that appears within another SQL data manipulation statement. If evaluated, the subquery gives a va

Number Types The Number types permit you to store the numeric data (real numbers, integers, and floating-point numbers), show quantities, and do computations. BINARY_INTEG

%NOTFOUND The %NOTFOUND is the logical opposite of the %FOUND. The %NOTFOUND yields TRUE when an INSERT, UPDATE, or DELETE statement affected no rows, or the SELECT INTO state

How Exceptions Propagate ? Whenever an exception is raised, and if the PL/SQL cannot find a handler for it in the present subprogram or block, the exception propagates. That is

Packages The package is a schema object which groups logically associated to the PL/SQL items, types, and subprograms. The Packages have 2 sections: the specification & the bod

DBMS: The answer to this question is of course given in of the theory book. This book is concerned with SQL DBMSs and SQL databases in particular. Soon we will be looking a