The package is a deceptively simple construct. In a small amount of time, you can learn all the basic elements of package syntax and rules, but you can spend weeks (or more) uncovering all the nuances and implications of the package structure. In this section, we review the rules you need to know in order to build packages. Later in the chapter, we’ll take a look at the circumstances under which you will want to build packages.
To construct a package, you must build a specification and, in almost every case, a package body. You must decide which elements go into the specification and which are hidden away in the body. You also can include a block of code that Oracle will use to initialize the package.
The specification of a package lists all the elements in that package that are available for use in applications, and provides all the information a developer needs in order to use elements defined in the package (often referred to as an “API” or Application Programming Interface). A developer should never have to look at the implementation code in a package body to figure out how to use an element in the specification.
Here are some rules to keep in mind for package specification construction:
You can declare variables and constants of almost any datatype, such as numbers, strings, and collections, at the package level (i.e., not within a particular procedure or function in the package). This is referred to as package-level ...