Forward Declarations Assignment Help

Assignment Help: >> Parameters - Forward Declarations

Forward Declarations:

PL/SQL needs a declaration an identifier before using it. For instance, the following declaration of procedure award_bonus is illegal because award_bonus calls 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 that case, this problem can be solved simply via placing procedure calc_rating before procedure award_bonus. Thus, the simple solution does not always work. For instance, consider the procedures are mutually recursive (call each other) or they are described in alphabetical order.

PL/SQL solves this problem through giving a special subprogram declaration known as a forward declaration. You could use forward declarations to

  • describe subprograms in alphabetical or logical order
  • describe mutually recursive subprograms
  • group subprograms in a package

 

A forward declaration consists of a subprogram specification terminated through a semicolon. In the subsequent instance, the forward declaration advises PL/SQL in which the body of procedure calc_rating can be found later in the block:

DECLARE

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

...

/* Define subprograms in alphabetical order. */

PROCEDURE award_bonus ( ... ) IS

BEGIN

calc_rating( ... );

... END;

PROCEDURE calc_rating ( ... ) IS

BEGIN

...

END;

While the formal parameter list appears in the further declaration, it must also appear in the subprogram body. A subprogram body can be placed anywhere after the forward declaration, but they must appear in the similar program unit.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd