Forward declarations - subprograms, PL-SQL Programming

Assignment Help:

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.


Related Discussions:- Forward declarations - subprograms

Relational shema.., Find the account numbers of all customers whose balance...

Find the account numbers of all customers whose balance is more than 10,000 $

Initializing records, Initializing Records The illustration below show...

Initializing Records The illustration below shows that you can initialize a record in its type definition. Whenever you declare a record of the type TimeRec, its 3 fields supp

Control structure, Control Structures The Control structures are the mo...

Control Structures The Control structures are the most important PL/SQL extension to the SQL. Not only does PL/SQL let you manipulate Oracle data, it lets you process the data

Rownum - sql pseudocolumns, ROWNUM The ROWNUM returns a number represe...

ROWNUM The ROWNUM returns a number representing the order in which a row was selected from the table. The first row selected has a ROWNUM of 1; the second row has a ROWNUM of

Built-in functions-comparison operators, Built-In Functions The PL/SQL p...

Built-In Functions The PL/SQL provides a lot of powerful functions to help you to manipulate the data. These built-in functions fall into the categories as shown below: error r

Example of not exists operator - sql, Example of NOT EXISTS Operator - SQL ...

Example of NOT EXISTS Operator - SQL Example is a translation into SQL of the corresponding example, which is included there merely to show that for any scalar comparison the

Exit statement - syntax, EXIT Statement   You can use the EXIT stateme...

EXIT Statement   You can use the EXIT statement to exit a loop. The EXIT statement has 2 forms: the conditional EXIT WHEN and the unconditional EXIT. With the either form, you

Initializing and referencing collections, Initializing and Referencing Coll...

Initializing and Referencing Collections Until you initialize a collection, a nested table or varray is automatically null (i.e. the collection itself is null, not its elements)

Anatomy of a command, Anatomy of a Command Figure, showing a simple S...

Anatomy of a Command Figure, showing a simple SQL command, is almost identical to its counterpart in the theory book. The only difference arises from the fact that SQL uses a

Using operator ref - manipulating objects pl sql, Using Operator REF: ...

Using Operator REF: You can retrieve refs by using the operator REF that, like VALUE, takes as its argument a correlation variable. In the illustration below, you retrieve one

Write Your Message!

Captcha
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