Say I have the Package below (please take note of the comments):
Create or replace package test_package_fdec as
procedure ext_proc1;
procedure ext_proc2;
end test_package_fdec;
/
Create or replace package body test_package_fdec as
procedure int_proc; -- forward declaration
procedure int_proc2 -- explicit internal procedure declaration
is
begin
dbms_output.put_line('this is int_proc2');
end int_proc2;
procedure ext_proc1
is
begin
dbms_output.put_line('Welcome to StackOverflow');
dbms_output.put_line('i will use an internal procedures with Forward Declarations');
int_proc;
end ext_proc1;
procedure ext_proc2
is
begin
dbms_output.put_line('Welcome to Oracle Forums');
dbms_output.put_line('i will use an internal procedures without Forward Declarations');
int_proc2;
end ext_proc2;
procedure int_proc
is
begin
dbms_output.put_line('used forward declaration');
end int_proc;
end test_package_fdec;
What is the Advantage/Disadvantage of using Forward Declaration in Internal Package Body Procedures? Does it have impact in Performance? In the same vein, are there any Advantage/Disadvantage in explicitly writing the internal procedure in the Declaration Section?
Forward declarations are not related to performance. They only exist for those rare cases where a procedure is called before it is declared.
The only time this is absolutely necessary is when two subprograms reference each other, like this:
Create or replace package body test_package_fdec as
procedure int_proc; -- forward declaration
procedure int_proc2
is
begin
dbms_output.put_line('this is int_proc2');
int_proc;
end int_proc2;
procedure int_proc
is
begin
dbms_output.put_line('this is int_proc2');
int_proc2;
end int_proc;
end test_package_fdec;
/
Sometimes forward declarations are useful for cosmetic reasons. It's important to list code in the order that makes sense to you, not necessarily the order in which it is called. Adding a forward declaration can help you keep the code in a more logical order.
The only downside to forward declarations is that some IDEs will not handle them properly. This can cause the object browser to get confused, and clicking on an object may take you to the forward declaration instead of the full code definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With