Skip to main content

Wrapping PL/SQL Code with DBMS_DDL Subprogram



 Here I am giving an example to wrap oracle plsql code with dbms_ddl subprogram.

Wrapping is the process of hiding PL/SQL source code. Wrapping helps to protect your source code by making it more difficult for others to view it.

The DBMS_DDL package contains procedures for wrapping a single PL/SQL unit, such as a package specification, package body, function, procedure, type specification, or type body. 

These overloaded subprograms provide a mechanism for wrapping dynamically generated PL/SQL units that are created in a database.

Oracle has given few Guidelines for Wrapping as below:
  • 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.
  • Wrap code only after you have finished editing it. You cannot edit PL/SQL source code inside wrapped files. Either wrap your code after it is ready to ship to users or include the wrapping operation as part of your build environment. To change wrapped PL/SQL code, edit the original source file and then wrap it again.
  • Before distributing a wrapped file, view it in a text editor to be sure that all important parts are wrapped.
There are few Limitations also:
  • Wrapping is not a secure method for hiding passwords or table names.
  • Wrapping does not hide the source code for triggers. To hide the workings of a trigger, write a one-line trigger that invokes a wrapped subprogram.
  • Wrapping does not detect syntax or semantic errors.
  • Wrapped PL/SQL units are upward-compatible between Oracle Database releases, but are not downward-compatible. For example, you can load files processed by the V8.1.5 wrap utility into a V8.1.6 Oracle Database, but you cannot load files processed by the V8.1.6 wrap utility into a V8.1.5 Oracle Database
  • It does not wrap PL/SQL content in anonymous blocks or triggers or non-PL/SQL code
Wrapping Package with DBMS_DDL.CREATE_WRAPPED Procedure,

DROP PACKAGE employee_actions;

DECLARE
  l_package_content  clob; -- text/clob for creating package spec and body
 
  FUNCTION get_sepc_content (pkgname VARCHAR2) RETURN VARCHAR2 AS
  BEGIN
    RETURN 'CREATE or replace  PACKAGE ' || pkgname || ' AUTHID DEFINER AS
    PROCEDURE increase_salary (p_emp_id NUMBER, p_salary NUMBER, p_commission NUMBER);
    
    PROCEDURE promote_employee (p_emp_id NUMBER, p_job VARCHAR2);
      
    PROCEDURE change_manager (p_emp_id NUMBER, p_mgr_id NUMBER);
    END ' || pkgname || ';';
  END get_sepc_content;
 
  FUNCTION get_body_content (pkgname VARCHAR2) RETURN VARCHAR2 AS
  BEGIN
    RETURN 'CREATE or replace PACKAGE BODY ' || pkgname || ' AS
     PROCEDURE increase_salary (p_emp_id NUMBER, p_salary NUMBER, p_commission NUMBER) 
IS
     BEGIN
       UPDATE emp
         SET sal = p_salary, comm = p_commission WHERE empno = p_emp_id;
       COMMIT;  
     END increase_salary;
      
     PROCEDURE promote_employee (p_emp_id NUMBER, p_job VARCHAR2) IS
     BEGIN
       UPDATE emp
         SET job = p_job WHERE empno = p_emp_id;
       COMMIT;  
     END promote_employee;
      
     PROCEDURE change_manager (p_emp_id NUMBER, p_mgr_id NUMBER) IS
     BEGIN
       UPDATE emp
         SET mgr = p_mgr_id WHERE empno = p_emp_id;
       COMMIT;  
     END change_manager;
   END ' || pkgname || ';';
  END get_body_content;
 
BEGIN
  l_package_content := get_sepc_content ('employee_actions');-- Generate package spec

  EXECUTE IMMEDIATE l_package_content;                -- Create package spec

  l_package_content := get_body_content ('employee_actions'); -- Generate package body

  SYS.DBMS_DDL.CREATE_WRAPPED (l_package_content);     -- Create wrapped package body
END;
/

Note: There is no legal way to unwrap a *.plb binary file (as said by Oracle). You are supposed to backup and keep your source files after wrapping them.

Output: Result is similar to,
Reference:
That's it.

Happy APEXing!!!...

Comments

  1. Wow what a great blog, i really enjoyed reading this, good luck in your work. Emotion Code

    ReplyDelete

Post a Comment

Popular posts from this blog

Printing Page Numbers in RTF Template [Oracle BI Publisher]

Here I am giving an example to print the page numbers dynamically in the RTF (Rich Text Format) template. Step 1:  Go to page footer and copy and paste the below script. Page |  <?fo:page-number?>  of  <?fo:page-number-citation:xdofo:lastpage-joinseq?> <fo:page-number> :   This is the object, which is used to represent the current page-number. <?fo:page-number-citation:xdofo:lastpage-joinseq?> :  This is the syntax, which is used to represent the total number of pages. Step 2:  Load the XML and preview the result. Output: That's it. References: fo:page-number Printing Page Number Code in Oracle XMLP RTF Template

Oracle Application Express Views (APEX)

Application Express Views Search SELECT * FROM apex_dictionary WHERE column_id = 0; View Comment Parent View APEX_APPLICATIONS Applications defined in the current workspace or database user. APEX_WORKSPACES APEX_APPLICATION_ALL_AUTH All authorization schemes for all components by Application APEX_APPLICATIONS

Save Selected Interactive Grid Records into a Collection - Oracle APEX

Here I am giving an example to save selected interactive grid records into a oracle apex collection. Step 1: Create a new blank page. Note: Mine was page 20. You will need to update reference to " P20 " with your page number if it's different. Step 2: Create a new interactive grid report region to the page using below query. Set Static Id "EmpDetails" to the region. SELECT  *     FROM   ( SELECT  emp . empno ,                emp . ename ,                emp . JOB ,                dept . dname department ,                dept . loc  LOCATION ,                mgr . ename  manager ,                emp . hiredate ,                 nvl ( emp . sal , 0 )  salary ,                 nvl ( emp . comm , 0 )  commission            FROM  eba_demo_chart_emp emp ,                eba_demo_chart_dept dept ,                eba_demo_chart_emp mgr           WHERE  emp . deptno = dept . deptno             AND  emp . mgr      = mgr . empno  ( + )           ORDER   BY  emp . ename