Forward declarations - subprograms, PL-SQL Programming

Forward Declarations

The PL/SQL needs that you declare an identifier before using it. And hence, you should declare a subprogram before calling it. For illustration, the declaration below of the procedure award_bonus is illegal as the award_bonus calls the procedure calc_ rating that is not yet declared when the call is made:

DECLARE

...

PROCEDURE award_bonus ( ... ) IS

BEGIN

calc_rating( ... ); -- undeclared identifier

...

END;

PROCEDURE calc_rating ( ... ) IS

BEGIN

...

END;

In this situation, you can solve the problem easily by placing the procedure calc_rating before procedure award_bonus. Though, the easy solution does not always work. For illustration, assume that the procedures are mutually recursive or you want to define them in the alphabetical order. The PL/SQL solves the problem by providing a special subprogram declaration known as the forward declaration. You can use the forward declarations to

(i) Define the subprograms in the logical or alphabetical order.

(ii)Define the mutually recursive subprograms.

(iii)Group the subprograms in a package.

The forward declaration consists of a subprogram specification completed by a semicolon. In the illustration shown below, the forward declaration suggested that the PL/SQL body of the procedure calc_rating can be found later in the block:

DECLARE

PROCEDURE calc_rating ( ... ); -- forward declaration

...

/* Define the subprograms in alphabetical order. */

PROCEDURE award_bonus ( ... ) IS

BEGIN

calc_rating( ... );

...

END;

PROCEDURE calc_rating ( ... ) IS

BEGIN

...

END;

Though the formal parameter list appears in the forward declaration, it should also appear in the subprogram body. You can position the subprogram body anywhere after the forward declaration, but they should appear in the same program unit.

Posted Date: 10/5/2012 5:26:21 AM | Location : United States







Related Discussions:- Forward declarations - subprograms, Assignment Help, Ask Question on Forward declarations - subprograms, Get Answer, Expert's Help, Forward declarations - subprograms Discussions

Write discussion on Forward declarations - subprograms
Your posts are moderated
Related Questions
On occasion, some of Brewbean's customers mistakenly leave an item out of a basket already checked out, so they create a new basket containing the missing items. However, they requ

Declaring Cursor Variables Once a REF CURSOR type is define by you, and then you can declare the cursor variables of that type in any PL/SQL block or subprogram. In the exampl

Iteration Schemes The bounds of a loop range can be variables, literals, variables, or expressions but must compute to integers. Below are some of the examples. As you can see t

LOB Types The large object (LOB) datatypes like BFILE, BLOB, CLOB, and NCLOB store the blocks of unstructured data (like graphic images, text, video clips, and sound waveforms)

Package STANDARD The package named STANDARD defines the PL/SQL atmosphere. The package specification globally declares the exceptions, types, and subprograms that are available

Cursor Variables Similar to a cursor, cursor variable points to the current row in the result set of a multi-row query. But, dissimilar a cursor, a cursor variable can be opene

Cursor Attributes   The Cursors and cursor variables have 4 attributes which give you helpful information about the execution of a data manipulation statement. Syntax:

THEO R Y OF SPECIAL CREATION - Life originated on the earth due to natural events by the super natural power. The biblical story of creation of world within six days was p

Name Resolution   During the compilation, the PL/SQL compiler relates identifiers like the name of a variable with an address or memory location, actual value, or datatype. Th

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