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.

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.