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
%FOUND Until the SQL data manipulation statement is executed, the %FOUND yields NULL. Afterward, the %FOUND yields TRUE, when an INSERT, UPDATE, or DELETE statement affected o

Project Description: I am looking to change FullCalendar to add/delete sql server data when events are removed or dropped from Calendar. Events should only be included by dra

Second Step at defining type SID in SQL CREATE TYPE SID AS VARCHAR(5) ; Explanation: TYPE SID announces that a type named SID is being defined to the system.

Error Handling The PL/SQL makes it easy to detect and process the predefined and user-defined error conditions known as exceptions. Whenever an error occurs, an exception is ra

Understanding Varrays The Items of type VARRAY are termed as the varrays. They permit you to relate a single identifier with the whole collection. This relationship lets you man

Implicit Cursor Attributes The Implicit cursor attributes returns the information about the execution of an INSERT, DELETE, UPDATE, or SELECT INTO statement. The cursor attribu

ROWID The ROWID returns the rowid (binary address) of a row in the database table. You can use the variables of the type UROWID to store rowids in a readable format. In the il

Introduction Oracle 9i - it was made public in the year 2001 with over 400 features, and graphics, it has merged the traditional business with modern internet application

Left and Right Joins LEFT OUTER JOIN can be used when you want to retrieve the data from the main table (table1) even if there is no match in other tables (table_2, table_3...

Count Operator in SQL Example: Counting the students who have scored more than 50 in some exam (SELECT COUNT (*) FROM (SELECT DISTINCT StudentId FROM EXAM_MARK WHE