tags:

views:

768

answers:

2

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?

+9  A: 

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.

Martlark
BTW you don't need the empty brackets ()
Jeffrey Kemp
@jeffrey Kemp - indeed - my lazy copying.
Martlark
A: 

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