Using Pragma in Oracle Package Body
- by asalamon74
I'd like to create an Oracle Package and two functions in it: A public function ( function_public ) and a private one ( function_private ). The public function calls the private one. I'd like to add the same pragma to the functions: WNDS, WNPS.
Without the pragma I can create a code like this:
CREATE OR REPLACE PACKAGE PRAGMA_TEST AS
FUNCTION function_public(x IN VARCHAR2) RETURN VARCHAR2;
END PRAGMA_TEST;
CREATE OR REPLACE PACKAGE BODY PRAGMA_TEST AS
FUNCTION function_private(y IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
-- code
END;
FUNCTION function_public(x IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
-- code
-- here is a call for function_private
-- code
END;
END PRAGMA_TEST;
If I'd like to add WNDS, WNPS pragma to function_public I should also add the same pragma to function_private because function_public calls function_private. It seems to me pragma can be used only in the package declaration, and not in package body, so I have to declare function_private in the package as well:
CREATE OR REPLACE PACKAGE PRAGMA_TEST AS
FUNCTION function_private(y IN VARCHAR2) RETURN VARCHAR2;
PRAGMA RESTRICT_REFERENCES( function_private, WNDS, WNPS);
FUNCTION function_public(x IN VARCHAR2) RETURN VARCHAR2;
PRAGMA RESTRICT_REFERENCES( function_public, WNDS, WNPS);
END PRAGMA_TEST;
CREATE OR REPLACE PACKAGE BODY PRAGMA_TEST AS
FUNCTION function_private(y IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
-- code
END;
FUNCTION function_public(x IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
-- code
-- here is a call for function_private
-- code
END;
END PRAGMA_TEST;
This solution makes my function_private public as well. Is there a solution to add pragma to a function which can be found only in the package body?