O'Reilly logo

Oracle PL/SQL Best Practices by Steven Feuerstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required