Skip to Main Content
  • Questions
  • Hiding Package Body Procedures and Functions for another user

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Shailendra.

Asked: August 13, 2024 - 6:37 am UTC

Last updated: August 21, 2024 - 5:24 am UTC

Version: 12c

Viewed 1000+ times

You Asked

Hi Tom,

First of all, I want to thank you for all the things which you have done and doing for Oracle community. It inspire me to learn more and more.

Now my question is --

Is there any way by which we can hide the procedures and functions code so the user can only execute it but cannot see and modify the code inside the package body ?

Thanks you!

and Connor said...

A package body in schema "X" cannot be seen from anyone outside schema "X" unless they are a DBA even if they have execution rights.


SQL> create or replace
  2  package MY_PKG is
  3    procedure P;
  4  end;
  5  /

Package created.

SQL>
SQL> create or replace
  2  package body MY_PKG is
  3    procedure P is
  4      x varchar2(100);
  5    begin
  6      select 'mysecretcode' into x from dual;
  7    end;
  8  end;
  9  /

Package body created.

SQL>
SQL>
SQL> grant execute on my_pkg to scott;

Grant succeeded.

SQL>
SQL> conn scott/tiger@pdb21a
Connected.
SQL> select text
  2  from all_source
  3  where name = 'MY_PKG';

TEXT
--------------------------------------------------
package MY_PKG is
  procedure P;
end;


Rating

  (2 ratings)

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

Comments

CREATE/DEBUG ANY PROCEDURE

Mikhail Velikikh, August 19, 2024 - 9:36 am UTC

> A package body in schema "X" cannot be seen from anyone outside schema "X" unless they are a DBA even if they have execution rights.

Anyone with CREATE ANY PROCEDURE or DEBUG ANY PROCEDURE will see package bodies as far as 19c is concerned. Don't need to be a DBA for that. DBA is just one of the roles that have those system privileges.
Connor McDonald
August 21, 2024 - 5:17 am UTC

Anyone with CREATE ANY PROCEDURE or DEBUG ANY PROCEDURE raises far more questions that being able to *see* code :-)

DBMS_DDL.WRAP

Jim Dickson, August 19, 2024 - 10:48 am UTC

Connor McDonald
August 21, 2024 - 5:24 am UTC

DDL wrap is useful but be aware there are plenty of unwrappers out there.

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