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
THEO R Y OF CATASTROPHISM OR CATALYSM (CUVIER 1769-1832) - The world has passed thorugh several stages and at the end of each stage there was a catastrophe killing all the

Parameter Aliasing   To optimize the subprogram call, the PL/SQL compiler can decide between the two techniques of the parameter passing. With the by-value techniques, the v

In Packages The Forward declarations also group logically related subprograms in the package. The subprogram specifications go in the package specification, & the subprogram b

Using a join on 3 tables, select 5 columns and 10 rows from the 3 tables without the use of a Cartesian product Query: SELECT E.LAST_NAME, E.FIRST_NAME, S.BUILDING, S.BRAN

Exceptions An exception is the runtime error or warning condition that can be predefined or user-defined. The Predefined exceptions are raised implicitly through runtime system

Functions   The function is a subprogram that calculates a value. The Functions and procedures are structured similar, except that the functions have a RETURN clause. You can

Semidifference and NOT - SQL In this section first describe the relational difference operator, named MINUS. Example here shows SQL's closest counterpart of that operator.

ROWID and UROWID Internally, every database table has a ROWID pseudo column that stores binary values known as rowids. Each rowid shows the storage address of a row. A physical

SQL Cursor   The Oracle implicitly opens a cursor to process each SQL statement not related with an explicit cursor. The PL/SQL refers to the most current implicit cursor as t

Parameter and Keyword Description: procedure_name The user-defined procedure is declared by this construct. parameter_name: This identifies the formal parameter t