Name

PKG-01: Group related data structures and functionality together in a single package.

Synopsis

Even if you don’t take advantage of features unique to packages, such as persistent data, you can still use packages to organize—and store together—related code and data structures.

Without packages, you might end up with several hundred standalone procedures and functions and many repeated cursor, TYPE, and variable declarations.

A package gives a name to a set of program elements: procedures, functions, user-defined types, variable and constant declarations, cursors, and so on. By creating a package for each distinct area of functionality, you create intuitive containers for that functionality.

Example

As I go about building a library management system, I quickly identify the following functional areas:

Borrower information

Maintain underlying table, establish rules about who is a valid borrower.

Book information

Maintain underlying table, define validation for ISBN, and so on.

Borrowing history

Maintain underlying table that tracks who took out what and when.

Overdue fines

Collection of all formulas and business rules for processing overdue charges.

Special reservations

Maintain underlying table and collect all rules governing how a borrower can reserve a book.

Publisher information

Maintain underlying table.

I can now create separate packages for each bunch of data or functional specification. For example, the overdue package would contain all programs related to calculating and displaying ...

Get Oracle PL/SQL Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.