Intermediate

Q:

17-6.

Prior to Oracle8i Release 8.1, it was necessary to add the RESTRICT_REFERENCES pragma for each function or procedure you wanted to enable for direct or indirect access from SQL. This pragma informs the compiler of how free or pure the program is from “side effects,” such as modifying data in the database.

Q:

17-7.

You can try to assert any combination of the following:

WNDS

Writes no database state; no modifications made to database tables.

WNPS

Writes no package state; no modifications made to package variables.

RNDS

Reads no database state; no queries against database tables or other database objects.

RNPS

Reads no package state; no read accesses of package variables.

Your program will not compile if you try to assert a purity level that is not supported by the code itself.

Q:

17-8.

You must supply the name of the program and then each of the purity levels:

CREATE OR REPLACE PACKAGE comp
IS
   FUNCTION total
      (sal_in IN NUMBER,
       comm_in IN NUMBER := NULL)
      RETURN NUMBER;

   PRAGMA RESTRICT_REFERENCES (
      total, WNDS, WNPS, RNDS, RNPS);
END;
/

Q:

17-9.

No program can be called directly or indirectly from SQL if it updates the database. At a minimum, you must include the following pragma to make the function usable:

PRAGMA RESTRICT_REFERENCES (my_function, WNDS);

Q:

17-10.

In Oracle 8.0 and earlier, you need to assert the WNPS purity level (in addition to the WNDS level) if you want to call a function:

  • In the WHERE, GROUP BY, or ORDER BY clauses of a SELECT statement

  • As a remote procedure call ...

Get Oracle PL/SQL Programming: A Developer's Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.