Oracle PL/SQL - mit "accessible by" Zugriffe in 12c auf PL/SQL einschränken

Aufgabe: Ein Package mit besonderen Rechten darf NUR von einem anderen Package aus aufgerufen werden, der User darf diese Package selber nicht aufrufen.

Lösung:

Beispiel Code:

 
-------------------
 
 
CREATE OR REPLACE PROCEDURE execute_proc
 accessible BY (gpi.call_proc)
IS
BEGIN
 DBMS_OUTPUT.put_line('-- Info :: Procedure execute_proc executed');
END;
/
 
 
-------------------
 
SQL> exec execute_proc
BEGIN execute_proc; END;
 
      *
ERROR AT line 1:
ORA-06550: line 1, column 7:
PLS-00904: insufficient privilege TO access object EXECUTE_PROC
 
 
-------------------
 
 
CREATE OR REPLACE PROCEDURE call_proc
IS
BEGIN
  execute_proc;
END;
/
 
 
-------------------
 
SQL> SET serveroutput ON
 
SQL> exec call_proc;
-- Info :: Procedure execute_proc executed
 
PL/SQL PROCEDURE successfully completed.

Nun kann execute_proc nur noch von der Procedure call_proc aufgerufen werden.

Aber! Beachten!

Aus der Doku:

The ACCESSIBLE BY clause allows access only when the call is direct. The check will fail if the access is through static SQL, DBMS_SQL, or dynamic SQL.

Quellen