Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute private procedures in an Oracle package?

Tags:

oracle

plsql

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?

like image 859
Margaret Avatar asked Dec 07 '22 07:12

Margaret


1 Answers

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.

like image 65
Martlark Avatar answered Dec 30 '22 11:12

Martlark