Search This Blog

Wednesday, October 6, 2010

Forward Declarations

"Declare elements before using them".


PL/SQL supports the forward declaration of local modules, which means that modules are declared in advance of the actual definition of that program. This declaration makes that program available to be called by other programs even before the program definition.

A forward declaration consists simply of the program header followed by a semicolon (;).This construction is called the module header.


Example:

PROCEDURE MY_TEST_PROCEDURE
IS

   FUNCTION X (..)  RETURN NUMBER;

   FUNCTION Y (..)  RETURN NUMBER;

   FUNCTION X (..) RETURN NUMBER  
   IS
   BEGIN
      -- Uses Function Y
   END X;

   FUNCTION Y(..)  RETURN NUMBER  
   IS
   BEGIN
      -- Uses Function X  
   END Y;
BEGIN
      -- Main logic
END MY_TEST_PROCEDURE;
/

Note:

We cannot make forward declarations of a variable or cursor.
This technique works only with modules (procedures and functions).


The definition for a forwardly declared program must be contained in the declaration section of the same PL/SQL block.

No comments:

Post a Comment