Monday, 28 October 2013

whatever procdure/function we define in package specification .. we need to define in package body. Variables need not be

In the package specification we have 2 procedures declared:

create or replace package package_temp is
         procedure proc1;
         procedure proc2;
         v_temp    varchar2(10);
end package_temp;

But, in the package body only proc1 is defined:

create or replace package body package_temp is
         procedure proc1 is
         begin
               dbms_output.put_line ('proc1 ');
         end proc1;
end package_temp;

This fails with compilation error:
  PLS-00323: subprogram or cursor 'proc2' is declared in a package specification and must be defined in the package body

This can be observed from user_errors table:
 
select *
from user_errors
where name like 'package_temp ';

The package body will be in INVALID state:

select *
from user_objects

where object_name like 'package_temp';

To correct the same, we need to define the proc2 as well:

create or replace package body package_temp is
           procedure proc1 is
           begin
               dbms_output.put_line ('proc1');
           end proc1;

           procedure proc2 is
           begin
                  dbms_output.put_line ('proc2');
           end proc2;
 end package_temp;

No comments:

Post a Comment