12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Managing PackagesYou can think of the spec as an interface and of the body as a black box. You candebug, enhance, or replace a package body without changing the package spec.The <strong>SQL</strong> CREATE PACKAGE statement is used to create package specification (specs).The CREATE PACKAGE BODY statement is used to define the package body.See Also:The spec holds public declarations, which are visible to stored procedures and othercode outside the package. You must declare subprograms at the end of the spec afterall other items (except pragmas that name a specific function; such pragmas mustfollow the function spec).The body holds implementation details and private declarations, which are hiddenfrom code outside the package. Following the declarative part of the package body isthe optional initialization part, which holds statements that initialize package variablesand do any other one-time setup steps.8.2 Managing SubprogramsSubprograms do not have to belong to a package. Program units that are createdoutside of a package are called stored or standalone subprograms. Stored subprogramscan be either functions or procedures. These subprograms are stored in the databaseand can be reused by multiple applications. Both procedures and functions can acceptparameters when they are executed (called). To execute a stored subprogram, you onlyneed to include its object name.A PL/<strong>SQL</strong> procedure is a subprogram that performs a specific action. You specify thename of the procedure, its parameters, its local variables, and the BEGIN-END blockthat contains its code and handles any exceptions. A function is a subprogram thatcomputes a value. Functions and procedures are structured alike, except that functionsreturn a value. For information on subprograms in PL/<strong>SQL</strong> blocks, see Using LocalPL/<strong>SQL</strong> Subprograms in PL/<strong>SQL</strong> Blocks.8.3 Managing Packages■■<strong>Oracle</strong> Database <strong>SQL</strong> Reference for information on the CREATEPACKAGE <strong>SQL</strong> statement.<strong>Oracle</strong> Database <strong>SQL</strong> Reference for information on the CREATEPACKAGE BODY <strong>SQL</strong> statement.With PL/<strong>SQL</strong>, you can break an application down into manageable, well-definedmodules. Using PL/<strong>SQL</strong> code, you can write program units that are stored as databaseobjects that can be reused. These objects include packages, subprograms, and triggers.Subprograms and packages are discussed in this topic; triggers are discussed inTriggers: Usage Information.When writing packages, keep them general so they can be reused in futureapplications. Become familiar with the <strong>Oracle</strong>-supplied packages, and avoid writingpackages that duplicate features already provided by <strong>Oracle</strong>.Design and define package specs before the package bodies. Place in a spec only thosethings that must be visible to calling programs. That way, other developers cannotbuild unsafe dependencies on your implementation details.To reduce the need for recompiling when code is changed, place as few items aspossible in a package spec. Changes to a package body do not require recompilingSubprograms and Packages: Usage Information 8-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!