在没有前向声明的情况下为另一个过程中的私有程序提供范围



我有一个软件包规范without_fwd,它具有公共过程p1和p2。

我也具有包体without_fwd,它具有三个过程p1,p2和p3。这里 p3 是在 p1 之后创建的私有过程,但在 p1 内部使用。

但是,为了在 p1 中使用 p3,我们可以使用前向声明来提供范围。

我需要知道是否有任何其他方法可以提供 p3 的作用域,以便我们可以在 p1 中调用它而无需使用前向声明

create or replace package without_fwd is
procedure p1;
procedure p2;
end without_fwd;
/
create or replace package body without_fwd is
procedure p1 is
begin
p3;
end;
procedure p2 is
begin
dbms_output.put_line('Success');
end;
procedure p3 is
begin
dbms_output.put_line('Success 2');
end;
end without_fwd;
/

对于家庭作业,我假设教授只是想让你先定义私有方法(顺便说一下,这通常比在现实世界中创建前向引用更常见(

create or replace package body without_fwd 
is
-- Private methods
procedure p3 is
begin
dbms_output.put_line('Success 2');
end;
-- Public methods
procedure p1 is
begin
p3;
end;
procedure p2 is
begin
dbms_output.put_line('Success');
end;
end without_fwd;

如果p3只在p1中使用,它可以被定义为p1的一部分,而不是包的私有方法。 在现实世界中,这有点不寻常 - 我从未真正见过经常使用这种方法的代码库,尽管我已经与使用这种方法的人交谈过。 我偶尔会使用它来简化数据更改的临时匿名块,但仅此而已。

create or replace package body without_fwd 
is
-- Public methods
procedure p1 
is
procedure p3 is
begin
dbms_output.put_line('Success 2');
end;
begin
p3;
end;
procedure p2 is
begin
dbms_output.put_line('Success');
end;
end without_fwd;

相关内容

最新更新