PL/SQL: Use pragma restrict_references to restrict package permissions and references

Source: Internet
Author: User

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;
/

 

 

 



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.