Prior to Oracle8i
Release 8.1, it was necessary to assert the purity level of a packaged
procedure or function when using it directly or indirectly in a SQL statement.
Beginning with Oracle8i Release 8.1, the PL/SQL runtime engine
determines a program's purity level automatically if no assertion exists.
The
RESTRICT_REFERENCES pragma asserts a purity level. The syntax for the
RESTRICT_REFERENCES pragma is:
PRAGMA
RESTRICT_REFERENCES (program_name |
DEFAULT, purity_level);
The keyword
DEFAULT applies to all methods of an object type or all programs in a package.
There can be
from one to five purity levels, in any order, in a comma-delimited list. The
purity level describes to what extent the program or method is free of side
effects. Side effects are listed in the following table with the purity
levels they address.
Purity
Level
|
Description
|
Restriction
|
WNDS
|
Write No Database State
|
Executes no INSERT, UPDATE, or DELETE
statements.
|
RNDS
|
Read No Database State
|
Executes no SELECT statements.
|
WNPS
|
Write No Package State
|
Does not modify any package variables.
|
RNPS
|
Read No Package State
|
Does not read any package variables.
|
TRUST (Oracle8i)
|
|
Does not enforce the restrictions
declared but allows the compiler to trust they are true.
|
The purity level
requirements for packaged functions are different depending on where in the SQL
statement the stored functions are used:
To be called
from SQL, all stored functions must assert WNDS.
All functions
not used in a SELECT, VALUES, or SET clause must assert WNPS.
To be executed
remotely, the function must assert WNPS and RNPS.
To be executed
in parallel, the function must assert all four purity levels or, in Oracle8i,
use PARALLEL_ENABLED in the declaration.
These functions
must not call any other program that does not also assert the minimum purity
level.
If a package has
an initialization section, it too must assert purity in Oracle7.
If a function is
overloaded, each overloading must assert its own purity level, and the levels
don't have to be the same. To do this, place the pragma immediately after each
overloaded declaration.
Many of the
built-in packages, including DBMS_OUTPUT, DBMS_PIPE, and DBMS_SQL, do not
assert WNPS or RNPS, so their use in SQL stored functions is necessarily
limited.
No comments:
Post a Comment