PL/SQL: Use pragma restrict_references to restrict package permissions and references
When looking at other people's code, we found the following compilation instructions,
Pragma restrict_references (get_attribute_name, wnds );
Get_attribute_name is a pl/SQL function. When I try to insert log information into a log table in this function, the compilation fails. The following information is provided,
Error (): PLS-00452: Subprogram 'get _ AMOUNT_NAME 'violates its associated pragma
It seems that the above pragma is a ghost. I checked the Oracle document (http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/restrictreferences_pragma.htm#LNPLS01339)
Only then can we know that the role of this pragma is to ensure that the function above will not change the State of the Database wnds (Write No Database State), but I Write the table in this function, no wonder this is a compilation error.
RESTRICT_REFERENCES pragma usage is as follows:
PRAGMA RESTRICT_REFERENCES (subprogram_name, [RNDS, WNDS, RNPS, WNPS, TRUST])
Keyword and parameter description:
PRAGMA: Indicates that this is a Compilation instruction and is executed during compilation.
Subprogram_name:PL/SQL function name
RNDS:(Read No Database State) indicates that the subprogram will not query tables in the (query) Database.
WNDS:(Write No Database State) indicates that the subprogram will not change the data of the table in the Database.
RNPS:(Read No Package State) does not access the variable in the Package
WNPS:(Write No Package State) does not change the variable value in the Package
TRUST:It indicates that trusting this subprogram will not violate any of the preceding constraints. It is generally used in PL/SQL to call external functions, such as java code.
Note that RESTRICT_REFERENCES pragma can only appear in package specification or object type specification.
The following is a simple example:
Create package loans
FUNCTION credit_ OK RETURN BOOLEAN;
PRAGMA RESTRICT_REFERENCES (credit_ OK, WNDS, RNPS );
END loans;
/