Available inDSQL

    Syntax

    Table 5.12.1.1 CREATE PACKAGE BODY Statement Parameters

    The CREATE PACKAGE BODY statement creates a new package body. The package body can only be created after the package header has been created. If there is no package header with name package_name, an appropriate error will be raised.

    All procedures and functions declared in the package header must be implemented in the package body. Additional procedures and functions may be defined and implemented in the package body only. Procedure and functions defined in the package body, but not defined in the package header are not visible outside the package body.

    The names of procedures and functions defined in the package body must be unique among the names of procedures and functions defined in the package header and implemented in the package body.

    Package procedure and function names may shadow global routines

    If a package header or package body declares a procedure or function with the same name as a stored procedure or function in the global namespace, it is not possible to call that global procedure or function from the package body. In this case, the procedure or function of the package will always be called.

    Rules

    • In the package body, all procedures and functions must be implemented with the same signature as declared in the header and at the beginning of the package body

    • The default values for procedure or function parameters cannot be overridden (as specified in the package header or in <package_item>). This means default values can only be defined in <package_body_item> for procedures or functions that have not been defined in the package header or earlier in the package body.

    Note

    UDF declarations (DECLARE EXTERNAL FUNCTION) is not supported for packages. Use UDR instead.

    5.12.1.1 Who Can Create a Package Body

    The CREATE PACKAGE BODY statement can be executed by:

    • Administrators

    • The owner of the package

    • Users with the ALTER ANY PACKAGE privilege

    5.12.1.2 Examples of CREATE PACKAGE BODY

    Creating the package body

    1. CREATE PACKAGE BODY APP_VAR
    2. AS
    3. BEGIN
    4. - Returns the start date of the period
    5. FUNCTION GET_DATEBEGIN() RETURNS DATE DETERMINISTIC
    6. AS
    7. BEGIN
    8. RETURN RDB$GET_CONTEXT('USER_SESSION', 'DATEBEGIN');
    9. END
    10. - Returns the end date of the period
    11. FUNCTION GET_DATEEND() RETURNS DATE DETERMINISTIC
    12. AS
    13. BEGIN
    14. RETURN RDB$GET_CONTEXT('USER_SESSION', 'DATEEND');
    15. PROCEDURE SET_DATERANGE(ADATEBEGIN DATE, ADATEEND DATE)
    16. AS
    17. BEGIN
    18. RDB$SET_CONTEXT('USER_SESSION', 'DATEBEGIN', ADATEBEGIN);
    19. RDB$SET_CONTEXT('USER_SESSION', 'DATEEND', ADATEEND);
    20. END
    21. END

    See alsoSection 5.12.2, ALTER PACKAGE BODY, , Section 5.12.4, RECREATE PACKAGE BODY,

    Used forAltering the package body

    Available inDSQL

    Syntax

    The ALTER PACKAGE BODY statement modifies the package body. It can be used to change the definition and implementation of procedures and functions of the package body.

    See Section 5.12.1, CREATE PACKAGE BODY for more details.

    5.12.2.1 Who Can Alter a Package Body

    The ALTER PACKAGE BODY statement can be executed by:

    • Administrators

    • The owner of the package

    • Users with the ALTER ANY PACKAGE privilege

    5.12.2.2 Examples of ALTER PACKAGE BODY

    1. ALTER PACKAGE BODY APP_VAR
    2. AS
    3. BEGIN
    4. - Returns the start date of the period
    5. FUNCTION GET_DATEBEGIN() RETURNS DATE DETERMINISTIC
    6. AS
    7. BEGIN
    8. RETURN RDB$GET_CONTEXT('USER_SESSION', 'DATEBEGIN');
    9. END
    10. - Returns the end date of the period
    11. FUNCTION GET_DATEEND() RETURNS DATE DETERMINISTIC
    12. AS
    13. BEGIN
    14. RETURN RDB$GET_CONTEXT('USER_SESSION', 'DATEEND');
    15. END
    16. - Sets the date range of the working period
    17. PROCEDURE SET_DATERANGE(ADATEBEGIN DATE, ADATEEND DATE)
    18. AS
    19. BEGIN
    20. RDB$SET_CONTEXT('USER_SESSION', 'DATEEND', ADATEEND);
    21. END

    See alsoSection 5.12.1, CREATE PACKAGE BODY, , Section 5.12.4, RECREATE PACKAGE BODY,

    Used forDropping a package body

    Available inDSQL

    Syntax

    Table 5.12.3.1 DROP PACKAGE BODY Statement Parameters

    ParameterDescription

    package_name

    Package name

    The DROP PACKAGE BODY statement deletes the package body.

    5.12.3.1 Who Can Drop a Package Body

    The DROP PACKAGE BODY statement can be executed by:

    • The owner of the package

    • Users with the ALTER ANY PACKAGE privilege

    5.12.3.2 Examples of DROP PACKAGE BODY

    Dropping the package body

    1. DROP PACKAGE BODY APP_VAR;

    See also, Section 5.12.2, ALTER PACKAGE BODY,

    Used forCreating a new or recreating an existing package body

    Available inDSQL

    Syntax

    The RECREATE PACKAGE BODY statement creates a new or recreates an existing package body. If a package body with the same name already exists, the statement will try to drop it and then create a new package body. After recreating the package body, privileges of the package and its routines are preserved.

    See Section 5.12.1, CREATE PACKAGE BODY for more details.

    5.12.4.1 Examples of RECREATE PACKAGE BODY

    Recreating the package body

    1. RECREATE PACKAGE BODY APP_VAR
    2. AS
    3. BEGIN
    4. - Returns the start date of the period
    5. FUNCTION GET_DATEBEGIN() RETURNS DATE DETERMINISTIC
    6. AS
    7. BEGIN
    8. RETURN RDB$GET_CONTEXT('USER_SESSION', 'DATEBEGIN');
    9. END
    10. - Returns the end date of the period
    11. FUNCTION GET_DATEEND() RETURNS DATE DETERMINISTIC
    12. AS
    13. BEGIN
    14. RETURN RDB$GET_CONTEXT('USER_SESSION', 'DATEEND');
    15. END
    16. - Sets the date range of the working period
    17. PROCEDURE SET_DATERANGE(ADATEBEGIN DATE, ADATEEND DATE)
    18. AS
    19. BEGIN
    20. RDB$SET_CONTEXT('USER_SESSION', 'DATEBEGIN', ADATEBEGIN);
    21. RDB$SET_CONTEXT('USER_SESSION', 'DATEEND', ADATEEND);
    22. END