Wrapping PL/SQL Source Code
Wrapping PL/SQL Source Code
This appendix explains what wrapping is, why you wrap PL/SQL code, and how to do it.
Topics:
Overview of Wrapping
Guidelines for Wrapping
Limitations of Wrapping
Wrapping PL/SQL Code with wrap Utility
Wrapping PL/QL Code with DBMS_DDL Subprograms
Overview of Wrapping
Wrapping is the process of hiding PL/SQL source code. Wrapping helps to
protect your source code from business competitors and others who might
misuse it.
You can wrap PL/SQL source code with either the wrap utility
or DBMS_DDL subprograms. The wrap utility wraps a single source file, such as a
SQL*Plus script. The DBMS_DDL subprograms wrap a single dynamically
generated PL/SQL unit, such as a single CREATE PROCEDUREstatement.
Wrapped source files can be moved, backed up, and processed by SQL*Plus and
the Import and Export utilities, but they are not visible through the static data
dictionary views *_SOURCE.
Note:
Wrapping a file that is already wrapped has no effect on the file.
Wrap only the body of a package or object type, not the specification.
This allows other developers to see the information they must use the
package or type, but prevents them from seeing its implementation.
Limitations of Wrapping
See Also:
wrap iname=/mydir/myfile
wrap iname=/mydir/myfile.sql oname=/mydir/myfile.plb
You can use the option oname to specify a different file name and extension:
wrap iname=/mydir/myfile oname=/yourdir/yourfile.out
Note:
If input_file is already wrapped, output_file will be identical to input_file .
Topics:
The CREATE [OR REPLACE] TRIGGER statement, and [DECLARE] BEGINEND anonymous blocks, are not wrapped. All other SQL statements are passed
unchanged to the output file.
All comment lines in the unit being wrapped are deleted, except for those in
a CREATE OR REPLACE header and C-style comments (delimited by /* */).
The output file is a text file, which you can run as a script in SQL*Plus to set up
your PL/SQL subprograms and packages. Run a wrapped file as follows:
SQL> @wrapped_file_name.plb;
emp_tab;
BEGIN
SELECT * BULK COLLECT INTO all_emps FROM employees;
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Emp Id: ' || all_emps(i).employee_id);
END LOOP;
END;
/
To wrap the file, run the following from the operating system prompt:
wrap iname=wrap_test.sql
If you view the contents of the wrap_test.plb text file, the first line
is CREATE PROCEDURE wraptest wrapped and the rest of the file contents is
hidden.
You can run wrap_test.plb in SQL*Plus to execute the SQL statements in the
file:
SQL> @wrap_test.plb
After the wrap_test.plb is run, you can execute the procedure that was
created:
SQL> CALL wraptest();
Note:
Wrapping a PL/SQL unit that is already wrapped has no effect on the unit.
Topics:
See Also:
Oracle Database PL/SQL Packages and Types Reference for information about
the DBMS_DDL package
END generate_body;
BEGIN
-- Generate package spec
package_text := generate_spec('emp_actions')
When you check the static data dictionary views *_SOURCE, the source is
wrapped, or hidden, so that others cannot view the code details. For example:
SELECT text FROM USER_SOURCE WHERE name = 'EMP_ACTIONS';
...