By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

How to call a private package level function

P: n/a
M
Hello

I am trying to build an Oracle PL/SQL Package. Some functions should
only be visible from the package, while other functions need to be
called from outside.

I tried the following:

-- begin code snippet ---

create or replace package test
is
FUNCTION MYPUBLICFUNC (parm in integer) return INTEGER;
end;
/
create or replace package body test
AS
FUNCTION MYPUBLICFUNC (parm in integer)
return integer
IS
BEGIN
RETURN test.MYPRIVATEFUNC(parm);
END;

FUNCTION MYPRIVATEFUNC (parm in integer)
return integer
IS
BEGIN
RETURN 3*parm;
END;
END;

-- End Code snippet ---

This results in an Error Message:
PLS-00013: MYPRIVATEFUNC ist für diesen Geltungsbereich nicht
definiert.

What am I doing wrong here ??

Kind Regards
Mat Hess

Please reply to the newsgroup
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I figured it out.

If I want a function or a procedure to be private, I just add it to
the body of the package. But note: The private function must be
declared before any code that calls it!

create or replace package test
is
FUNCTION MYPUBLICFUNC (parm in integer) return INTEGER;
end;
/
create or replace package body test
AS
-- MUST Declare HERE
FUNCTION MYPRIVATEFUNC (parm in integer)
return integer
IS
BEGIN
RETURN 3*parm;
END;

FUNCTION MYPUBLICFUNC (parm in integer)
return integer
IS
BEGIN
RETURN test.MYPRIVATEFUNC(parm);
END;

-- MUST NOT DECARE HERE!!
END;

Regards Mat

Jul 19 '05 #2

P: n/a
JT
Not quite true. You can use a forward declaration in order to keep the
sub-programs in the order you require:

create or replace package test
is
FUNCTION MYPUBLICFUNC (parm in integer) return INTEGER;
end;
/
create or replace package body test
AS
FUNCTION myprivatefunc(parm IN INTEGER) RETURN INTEGER;

FUNCTION MYPUBLICFUNC (parm in integer)
return integer
IS
BEGIN
RETURN test.MYPRIVATEFUNC(parm);
END;

FUNCTION MYPRIVATEFUNC (parm in integer)
return integer
IS
BEGIN
RETURN 3*parm;
END;

END;
/
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.