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-12: Use a standard format for packages that include comment headers for each type of element defined in the package.

Synopsis

Packages are likely to be the largest, most complex code elements of your application. The internal structure of a package (both the specification and the body) is usually composed of many different types of elements, including variables, user-defined types, functions, and procedures.

Your standard package format should help you organize the elements of a package, minimize the need for forward declarations, and make it easier for you to rapidly find constructs. Make the standard format available for developers either in a template file or by generating it upon command.

Example

Here’s a template for a package body (see Section for where to find this code):

CREATE OR REPLACE PACKAGE BODY name
IS
/*
PUT YOUR PACKAGE HEADER HERE
*/

/* Constants */

/* Variables */

/* Exceptions */

/* Types (records, collections, cursor variables) */

/* Private Programs */

/* Public Programs */

END name;

Benefits

If everyone in your development team builds packages the same way, it will be easier to maintain the code base.

By separating code elements into distinct sections identified by headers, you can quickly find the desired code.

Resources

  1. template.pks and template.pkb : Template files, one for the package specification and one for the body.

  2. PLVgen: Use this package of the PL/Vision library to generate a package template, either to the screen or directly to a file.

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