Wrap and compile in one step
Posted by Tyler Muth on September 14, 2007
The PL/SQL wrap utility is a great way to obfuscate code that you do not want anyone to view. Typically this is used for security functions Virtual Private Database and Fine Grained Auditing policies, encryption and hashing functions, and authentication and authorization procedures. The source of unwrapped code can easily be retrieved from the ALL_SOURCE view or almost any IDE that connects to the database.
Prior to 10g, you needed to use the command-line wrap binary located in $ORACLE_HOME/bin. This was a 2 step process, requiring you to first wrap the code from the shell, then compile it using SQL*Plus. 10g introduced the DBMS_DDL package, allowing you to wrap code from within PL/SQL and compile it in one step. This means you don’t need to be on a machine where Oracle is installed, allowing you to use other tools such as APEX and SQL Developer to wrap your code.
Here’s a quick example:
-- Run the following grant as sys: -- grant execute on dbms_ddl to demo; declare l_function varchar2(32767); begin l_function := q'! create or replace function wrap_test return varchar2 is begin return 'Yep, it worked'; end wrap_test; !'; -- Toggle the comments on the following 2 lines to toggle wrapped / not wrapped -- execute immediate l_function; sys.dbms_ddl.create_wrapped(l_function); end; /