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
Opening a Cursor Opening the cursor executes the query & identifies the result set that consists of all rows that meet the query search criteria. For the cursors declared usin

Consider the following set of database tables (same tables from Assignment 6-1). Please take note of foreign keys (most of them carry the same names as the corresponding primary ke

Relational Operators The relational operators permit you to compare randomly complex expressions. The list below provides the meaning of each operator:

EXECUTE IMMEDIATE Statement   The EXECUTE IMMEDIATE statement prepare (parses) and instantly executes a dynamic SQL statement or an anonymous PL/SQL block. Syntax:

Data Types in SQL - Timestamp TIMESTAMP for values representing points in time on a specified uniform scale. DATE is used for timestamps on a scale of one day, such as DATE '2

JOIN and AND in SQL In this Section is all about one operator, JOIN. SQL's closest counterpart, NATURAL JOIN, has already been covered. Here we look at several other "join" op

UNION without CORRESPONDING - SQL The use of UNION without CORRESPONDING. Example is merely by omitting CORRESPONDING, but only because the operands have identical SELECT clau

Use External Routines The PL/SQL is particular for the SQL transaction processing. Therefore, several tasks are more quickly completed in a lower-level language like C that is

At times, Brewbean's has changed the id number for existing products. In the past, they have had to add a new product row with the new id to the BB_PRODUCT table, modify all the co

Keyword and Parameter Description: label_name: This is an undeclared identifier which labels an executable statement or the PL/SQL block. You can use a GOTO statement to