Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Rajeshwaran.

Asked: April 19, 2017 - 2:18 pm UTC

Last updated: April 19, 2017 - 4:15 pm UTC

Version: 12.2.0.1

Viewed 1000+ times

You Asked

Team,

Reading through the "accessible by" clause enhancements in 12.2

http://docs.oracle.com/database/122/LNPLS/release-changes.htm#GUID-85A17D6B-4E7A-49D9-B5AC-B0D69390B449

<quote>
Starting with Oracle Database 12c release 2 (12.2), the accessor list can be defined on individual subprograms in a package. This list is checked in addition to the accessor list defined on the package itself (if any). This list may only restrict access to the subprogram – it cannot expand acces
</quote>

demo@ORA12C> create or replace package mypkg
  2  as
  3     function f return number accessible by (p1);
  4     procedure p2;
  5  end;
  6  /

Package created.

demo@ORA12C> create or replace package body mypkg
  2  as
  3     function f return number
  4     accessible by (p1)
  5     as
  6     begin
  7             return 55;
  8     end ;
  9
 10     procedure p2 as
 11     begin
 12             dbms_output.put_line('Result = '||mypkg.f);
 13     end;
 14  end;
 15  /

Package body created.

demo@ORA12C> exec dbms_output.put_line( mypkg.f );
BEGIN dbms_output.put_line( mypkg.f ); END;

                                  *
ERROR at line 1:
ORA-06550: line 1, column 35:
PLS-00904: insufficient privilege to access object F


demo@ORA12C> exec mypkg.p2 ;
Result = 55

PL/SQL procedure successfully completed.


The access list for the function F in the package is defined only for P1, but it is still accessible by another method "P2" from the same package, is this an expected behavior? please confirm.

with LiveSQL Test Case:

and Chris said...

If you follow the links to the accessible by clause definition you'll find:

A unit can always access itself. An item in a unit can reference another item in the same unit.

http://docs.oracle.com/database/122/LNPLS/ACCESSIBLE-BY-clause.htm#LNPLS-GUID-9720619C-9862-4123-96E7-3E85F240FF36

So yes, this is expected behaviour.

PS - If posting a LiveSQL link, you're supposed to save your script and put that link in the form...

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library