userimage

Forward declaration

Hi,

What is forward declaration. Where we will use this concept.

Please explain Breifly

userimage
Before going to use the procedure in any other subprogram or other block , you must declare the prototype of the procedure in declarative section.

CREATE OR REPLACE PACKAGE BODY demo_pkg
AS
   PROCEDURE p
   IS
   BEGIN
      p2;
   END;

   PROCEDURE p2
   IS
   BEGIN
      NULL;
   END;
END;

Warning: Package Body created with compilation errors.

that fails because  p doesn't know about p2 yet, so you can do like below:

 create or replace package body demo_pkg
    as
            procedure p2;    --  forward declaration
            procedure p
            is
            begin
                    p2;
            end;

           procedure p2
           is
           begin
                   null;
           end;
   end;
   /

Package body created.
Answer is