dbTalk Databases Forums  

How to call a private package level function

comp.databases.oracle comp.databases.oracle


Discuss How to call a private package level function in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
M
 
Posts: n/a

Default How to call a private package level function - 08-13-2004 , 09:35 AM






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

Reply With Quote
  #2  
Old   
Mat Hess
 
Posts: n/a

Default Re: How to call a private package level function - 08-14-2004 , 02:54 PM






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


Reply With Quote
  #3  
Old   
JT
 
Posts: n/a

Default Re: How to call a private package level function - 08-16-2004 , 06:18 AM



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;
/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.