借助以下实验数据进行分析

创建四个过程:

create or replace procedure p1
is
 v_name scott.emp.ename%type;
begin
  select scott.emp.ename into v_name
  from scott.emp
  where scott.emp.empno = '7521';
end;


create or replace procedure p2
is
begin
  p1;
end;


create or replace procedure p3
is
begin
  p2;
end;

create or replace procedure p4
is
begin
 p3;
end;

我们可以看出来,过程p2调用p1,p3调用p2,以此类推;接下来我们运用代码来查看每个过程的状态:

select object_name,status
from user_objects
where object_name in ('P1','P2','P3','P4');

得到结果:

OBJECT_NAME STATUS
P1 VALID
P2 VALID
P3 VALID
P4 VALID

我们可以看出来,在依次创建四个过程后,四个过程均为可用状态,下面接着把过程p1作如下改变:

create or replace procedure p1
is
 v_name scott.emp.ename%type;
begin
  select scott.emp.ename into v_name
  from scott.emp
  where scott.emp.empno = '7499';
end;

再次查看四个过程的状态如下所示:

OBJECT_NAME STATUS
P1 VALID
P2 INVALID
P3 INVALID
P4 INVALID

这个结果表示,对p2过程的解析已经不再和现在的p1过程有关系,如果调用p2,则需要重新进行编译。

例子2:

创建四个包:

create or replace package pkg1 is
procedure p1; end;

create or replace package body pkg1 is
procedure p1 is
 v_name varchar(12);
 begin
   select scott.emp.ename into v_name
   from scott.emp
   where scott.emp.empno = '7566';
   dbms_output.put_line(v_name);
 end;
end;


create or replace package pkg2 is
procedure p2; end;

create or replace package body pkg2 is
 procedure p2 is
 begin
   pkg1.p1;
 end;
end;


create or replace package pkg3 is
procedure p3; end;

create or replace package body pkg3 is
procedure p3 is
 begin
   pkg2.p2;
 end;
end;


create or replace package pkg4 is
procedure p4; end;

create or replace package body pkg4 is
procedure p4 is
 begin
  pkg3.p3;
 end;
end;

我们可以看出来,包pkg2中的过程p2调用包pkg1中的过程p1,以此类推;接下来我们运用代码来查看每个过程的状态:

select object_name,object_type,status
from user_objects
where object_name in ('PKG1','PKG2','PKG3','PKG4');

得到结果:

OBJECT_NAME OBJECT_TYPE STATUS
PKG1 PACKAGE VALID
PKG1 PACKAGE BODY VALID
PKG2 PACKAGE VALID
PKG2 PACKAGE BODY VALID
PKG3 PACKAGE VALID
PKG3 PACKAGE BODY VALID
PKG4 PACKAGE VALID
PKG4 PACKAGE BODY VALID

我们可以看出来,在依次创建四个包后,四个包均为可用状态,下面接着把包pkg1作如下改变:

create or replace package pkg1 is
procedure p1; end;

create or replace package body pkg1 is
procedure p1 is
 v_name varchar(12);
 begin
   select scott.emp.ename into v_name
   from scott.emp
   where scott.emp.empno = '7566';
   dbms_output.put_line(v_name);
 end;
end;

创建成功后我们再做测试,结果如下:

OBJECT_NAME OBJECT_TYPE STATUS
PKG1 PACKAGE VALID
PKG1 PACKAGE BODY VALID
PKG2 PACKAGE VALID
PKG2 PACKAGE BODY VALID
PKG3 PACKAGE VALID
PKG3 PACKAGE BODY VALID
PKG4 PACKAGE VALID
PKG4 PACKAGE BODY VALID

这个结果表示,对包pkg2中的p2的解析和现在的包pkg1中的p1仍有关系,如果调用p2,则不需要重新进行编译。

而重新编译是很耗费资源的。