Tutorial :How do I execute private procedures in an Oracle package?



Question:

This is my first attempt at creating a package, so I must be missing something really really obvious (nothing that I've Googled for seems to even consider it worth mentioning).

Obviously, if you have procedures in your package body that are not included in the specification section, then those procedures are private. The problem I've got is that I can't seem to figure out how to reference those private packages once I've made them. And SQL Developer refuses to give me any message more useful than 'execution completed with warning', which doesn't help...

As an example, this is what I've been trying that doesn't work (just throws the aforementioned compiler error):

CREATE OR REPLACE PACKAGE BODY testPackage AS    PROCEDURE privateProc; --Forward declaration    PROCEDURE publicProc IS  BEGIN      EXECUTE privateProc();  END;    PROCEDURE privateProc IS  BEGIN      DBMS_OUTPUT.PUT_LINE('test');  END;    END testPackage;  

I've also tried referring to it as testPackage.privateProc, which hasn't worked either.

What am I doing wrong?


Solution:1

I think you should do this:

CREATE OR REPLACE PACKAGE BODY testPackage AS  PROCEDURE privateProc; --Forward declaration    PROCEDURE publicProc IS    BEGIN          privateProc();  END;    PROCEDURE privateProc IS  BEGIN        DBMS_OUTPUT.PUT_LINE('test');  END;  END testPackage;  

Just call privateProc as if it is part of the language. Execute is for running DML or SQL inside your PL/SQL.


Solution:2

CREATE OR REPLACE PACKAGE BODY testPackage AS    PROCEDURE publicProc; --Forward declaration    PROCEDURE publicProc IS  BEGIN  privateProc; --exec privateProc;  END;    PROCEDURE privateProc IS  BEGIN  DBMS_OUTPUT.PUT_LINE('test');  END;    END testPackage;    //call testPackage.publicProc  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »