3.8 Managing Packages

A package is a database object that groups logically related PL/SQL types, items, functions and procedures. Use Object Browser to view, create, edit, download, and drop packages.

Packages usually have two parts, a specification and a body. The specification is the interface to your application. The body implements the specification.

See Also:

PL/SQL Packages and PL/SQL Subprograms in Oracle Database PL/SQL Language Reference for additional information on PL/SQL packages.

3.8.1 Creating a Package

Create packages using Object Browser.

To create a package:

  1. In Object Browser, click the Create Database Objects menu and select Package.

    Tip:

    To create new objects from the Object Tree, right-click the object and select the Create option.

    The Create Package Wizard appears.

  2. On Create Package:
    1. Name - Enter the name of the package to be created. The name must conform to Oracle naming conventions and cannot contain spaces, or start with a number or underscore.
    2. Include Sample Code - Specify whether to include sample code while creating the package. Enable or disable this option.
  3. Click Create Package.

3.8.2 Viewing a Package

Select a package from the Object Tree and access tabs in the Object Detail View.

To view a package:

  1. In Object Browser, Object Tree, expand Packages and select a package.
  2. The Object Detail View appears and displays five tabs:

    Tip:

    The Specification and Body tabs feature a fully functional Code Editor. To learn more about the Code Editor, see Code Editor in Object Browser.
    • Specification - Displays the package specification. The package specification defines the interface to your application and delcares the elements that can be referenced outside of the package. You can edit the code in this view using a fully functional Code Editor. Available actions include:
      • Download
      • Save and Compile
      • Drop.
      • Refresh
    • Body - Displays the package body. The packge body is named collection of functions, procedures, variables, cursors, user-defined types, and records that are referenced using the package name. You can edit the code in this view using a fully function Code Editor. Available actions include:
      • Download
      • Save and Compile
      • Drop.
      • Refresh
    • Dependencies - Displays objects that use (or depend on) on the current package and objects the package depends on. Available actions include Refresh.
    • Errors - Lists errors related to the current package. Available actions include Refresh.
    • Grants - Lists details of grants for the current package, including privilege, grantee, grantable, grantor, and object name. Available actions include:
      • Grant
      • Revoke
      • Refresh

3.8.3 Editing a Package Manually

Select a package from the Object Tree and edit the code in the Object Detail View.

When you edit a package, you can edit the code manually, perform a search and replace, and then compile the package.

To edit a package manually:
  1. In Object Browser, Object Tree, expand Packages and select a package.

    The Object Detail View appears.

    The Specification tab defines the interface to your application. The Body tab displays the package body, if one exists, for the selected package.

  2. Select the appropriate tab (Specification or Body) and edit the source code directly using the Code Editor.

    Tip:

    To learn more about the Code Editor, see Code Editor in Object Browser.

    If you edit and make changes to a view, you must compile to save your changes.

  3. Click Save and Compile to compile the current package.

    Compiling re-creates the object in the database. If the compilation fails, an error message displays above the code.

3.8.4 Compiling a Package

Select a package from the Object Tree and click Save and Compile.

If you edit and make changes to a package, you must compile to save your changes.

The Save and Compile action is available on both the Specification and Body tabs in Object Detail View.

To compile a package:

  1. In Object Browser, Object Tree, expand Packages and select a package.

    The Object Detail View appears.

  2. Click the appropriate tab (Specification tab or Body) and then click Save and Compile.

    Compiling re-creates the object in the database. If the compilation fails, an error message displays above the code.

3.8.5 Downloading a Package

Select a package from the Object Tree and click Download to save it as a file.

Both the Specification and Body tabs feature a fully functional Code Editor. To download the displayed source code in either tab, click Download.

To download a package:

  1. In Object Browser, Object Tree, expand Packages and select a package.

    The Object Detail View appears.

  2. To save the current package as a file:
    1. Select the appropriate tab (Specification or Body).
    2. Click Download .

3.8.6 Dropping a Package While Viewing the Specification

Select a package from the Object Tree and click Drop on the Specification tab.

The package specification defines the interface to your application and delcares the elements that can be referenced outside of the package.

To drop a package specification:

  1. In Object Browser, Object Tree, expand Packages and select a package.

    The Object Detail View appears.

  2. On the Specification tab, click Drop.
    1. Drop - Review the details.
    2. SQL - Displays the SQL generated to drop the package. To copy the displayed SQL, click the Copy icon.
    3. To confirm your selection, click Drop again.

3.8.7 Dropping a Package While Viewing the Body

Select a package from the Object Tree and click Drop on the Body tab.

The package body is a named collection of functions, procedures, variables, cursors, user-defined types, and records that are referenced using the package name.

To drop a package while viewing the Body:

  1. In Object Browser, Object Tree, expand Packages and select a package.

    The Object Detail View appears.

  2. On the Body tab, click Drop.

    In the Drop dialog:

    1. Drop - Review the details.
    2. SQL - Displays the SQL generated to drop the package body. To copy the displayed SQL, click the Copy icon.
    3. Confirm your selection and click Drop again.