Chapter 6 - PLV: Top-Level Constants and Functions

advanced oracle pl/sql programming with packages

Chapter 6
 

6. PLV: Top-Level Constants and Functions

Contents:
Null Substitution Value
Setting the PL/Vision Date Mask
Assertion Routines
PLV Utilities
The Predefined Datatypes
The Predefined Constants

Let's start our exploration into PL/Vision with the PLV package, which can be considered the lowest-level package or perhaps even the "miscellaneous" package. It provides a single collection point for constants and basic functions used throughout PL/Vision. Whenever I thought of something useful that was needed in more than one package but that did not belong in any particular functional package, it ended up in PLV.

The PLV (PL/Vision) package offers the following:

  • A NULL substitution value. You can set in PLV the string you want to use in place of NULL for display purposes.

  • A product-wide date mask. You can set a date mask that will be used throughout PL/Vision when converting and displaying dates. You can also use this mask yourself in SQL and PL/SQL.

  • A set of assertion routines. These programs help you construct more robust applications by letting you easily verify assumptions.

  • Miscellaneous utilities. You can obtain the current date and time, pause your PL/SQL program, obtain the error message for an Oracle error number, and more.

  • A set of constants used throughout PL/Vision. These named constants help users of PL/Vision (and packages within PL/Vision) avoid hard-coding literals.

  • Predefined datatypes. PL/Vision uses these datatypes as anchors (with the %TYPE declaration attribute) for declaring other variables. You might use them, too, or you might simply follow the example in your own applications.

The following sections show how to use each of the different elements in the PLV package.

6.1 Null Substitution Value

It has been my experience that when I display a variable that is NULL, I want to see some evidence of that fact. In fact, I have found that in several places in PL/Vision I want to be able to substitute a NULL value for some other string. Rather than hard code that value into my package, I added the ability in the PLV package to decide what the substitution value would be with the set_nullval procedure:

PROCEDURE set_nullval (nullval_in IN VARCHAR2);

The default value for NULL substitutions is the string NULL. You can obtain the current setting of the substitution value by calling the nullval function:

FUNCTION nullval RETURN VARCHAR2;

The p package makes use of the substitute value for NULLs. When you call p.l to display text that RTRIMs to a NULL, it will automatically display the string that you have specified for substitution. In the following example, I set the NULL substitution value to N/A and then demonstrate its use in a call to the p.l procedure.

SQL> exec PLV.set_nullval ('N/A'); SQL> VARIABLE v NUMBER; SQL> exec p.l (:v); N/A


III. Building Block Packages6.2 Setting the PL/Vision Date Mask

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.



Advanced Oracle PL. SQL Programming with Packages
Advanced Oracle Pl/Sql: Programming With Packages (Nutshell Handbook)
ISBN: B00006AVR6
EAN: N/A
Year: 1995
Pages: 195
Authors: Steven Feuerstein, Debby Russell
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net