如何在不删除包的情况下更改包oracle

时间:2013-06-07 15:53:05

标签: database oracle package alter

我需要在不删除软件包的情况下向此软件包添加功能吗?只需添加另一个功能。

    DROP PACKAGE BANINST1.SB_ENROLLMENT
    CREATE OR REPLACE PACKAGE BANINST1.sb_enrollment AS
     FUNCTION f_query_all_active_ptrm ()
          RETURN enrollment_ref;
    END sb_enrollment;
    DROP PACKAGE BODY BANINST1.SB_ENROLLMENT
    /


    CREATE OR REPLACE PACKAGE BODY BANINST1.sb_enrollment AS
    FUNCTION f_query_all_active_ptrm ()
          RETURN enrollment_ref;
       BEGIN
       END f_query_all_active_ptrm;
    END sb_enrollment;

1 个答案:

答案 0 :(得分:4)

你不能ALTER一个包来添加新功能。但是,由于您使用的是CREATE OR REPLACE,因此无需DROP包或包体。由于包是单个对象,因此您需要完整地替换包规范和包体(因此您需要包括所有现有的功能和过程)。

CREATE OR REPLACE PACKAGE BANINST1.sb_enrollment 
AS
  FUNCTION f_query_all_active_ptrm ()
    RETURN enrollment_ref;

  FUNCTION new_function_name
    RETURN number;
END sb_enrollment;

CREATE OR REPLACE PACKAGE BODY BANINST1.sb_enrollment 
AS
  FUNCTION f_query_all_active_ptrm ()
    RETURN enrollment_ref;
   BEGIN
     <<some implementation>>
   END f_query_all_active_ptrm;

  FUNCTION new_function_name
    RETURN number
  IS
  BEGIN
    RETURN 1;
  END;
END sb_enrollment;