The package specification contains public declarations. The declared items are accessible from anywhere in the package and to any other subprograms in the same schema. Figure 10-1 illustrates the scoping.
Description of Package Scope"
The spec lists the package resources available to applications. All the information your application must use the resources is in the spec. For example, the following declaration shows that the function named factorial takes one argument of type INTEGER and returns a value of type INTEGER:
FUNCTION factorial (n INTEGER) RETURN INTEGER; -- returns n!
That is all the information needed to invoke the function. You need not consider its underlying implementation (whether it is iterative or recursive for example).
If a spec declares only types, constants, variables, exceptions, and call specifications, the package body is unnecessary. Only subprograms and cursors have an underlying implementation. In Example 10-1, the package needs no body because it declares types, exceptions, and variables, but no subprograms or cursors. Such packages let you define global variables, usable by stored subprograms and triggers, that persist throughout a session.
A Simple Package Specification Without a Body
CREATE PACKAGE trans_data AS -- bodiless package
TYPE TimeRec IS RECORD (
TYPE TransRec IS RECORD (
minimum_balance CONSTANT REAL := 10.00;