The PRAGMA Keyword
A programming notion that is truly derived from Greek is pragma, which means “deed”
or, by implication, an “action.” In various programming languages, a pragma is gen-
erally a line of source code prescribing an action you want the compiler to take. It’s like
an option that you give the compiler; it can result in different runtime behavior. for the
program, but it doesn’t get translated directly into bytecode.
PL/SQL has a PRAGMA keyword with the following syntax:
PRAGMA instruction_to_compiler;
The PL/SQL compiler will accept such directives anywhere in the declaration section,
but most of them have certain additional requirements regarding placement.
PL/SQL offers several pragmas:
AUTONOMOUS_TRANSACTION
Tells the PL/SQL runtime engine to commit or roll back any changes made to the
database inside the current block without affecting the main or outer transaction.
EXCEPTION_INIT
Tells the compiler to associate a particular error number with an identifier you have
declared as an exception in your program. Must follow the declaration of the
exception.
RESTRICT_REFERENCES
Tells the compiler the purity level (freedom from side effects) of a packaged pro-
gram.
SERIALLY_REUSABLE
Tells the PL/SQL runtime engine that package-level data should not persist be-
tween references to that data. See Chapter 18 for more information.
The following block demonstrates the use of the EXCEPTION_INIT pragma to name
a built-in exception that would otherwise have only a number:
DECLARE
no_such_sequence EXCEPTION;
PRAGMA EXCEPTION_INIT (no_such_sequence, −2289);
BEGIN
...
EXCEPTION
WHEN no_such_sequence
THEN
q$error_manager.raise_error ('Sequence not defined');
END;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17309626/viewspace-625615/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/17309626/viewspace-625615/