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
Defining Autonomous Transactions To define an autonomous transaction, you use the pragma (compiler directive) AUTONOMOUS_TRANSACTION. The pragma instructs the PL/SQL compiler

CLOSE Statement The CLOSE statement allows the resources held by a cursor variable or open cursor to be reused. No more rows can be fetched from the cursor variable or closed

Why Use Cursor Variables ? Primarily, you use the cursor variables to pass the query result sets between the PL/SQL stored subprograms and different clients. Neither PL/SQL nor

%NOTFOUND The %NOTFOUND is logical, opposite of the %FOUND. The %NOTFOUND yields FALSE if the last fetch returned a row, or TRUE when the final fetch failed to return a row. I

SQL Is a Database Language: The commands given to a DBMS by an application are written in the database language of the DBMS. The term data sublanguage is sometimes used instea

The SQL ‘CREATE TABLE' scripts for all the tables you have implemented. Note that your tables must correspond exactly to the ERD you have provided in 1. above, or you will lose ma

Structure of an Object Type: Similar to package, an object type has 2 parts: the specification and the body. The specification is the interface to your applications; it declar

Complete the following steps to create a procedure to calculate the tax on an order. The BB_TAX table contains the states that require taxes to be submitted for Internet sales. If

write the program for traffic control system with 10 second, 15 secod, and 20 second delay

Grouping and Ungrouping in SQL Example specifying EXAM_MARK in place of COURSE in the main FROM clause. Example: Obtaining C_ER2 from EXAM_MARK SELECT CourseId, CAST