Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return value from procedure 2

Status
Not open for further replies.

slok

Programmer
Jul 2, 1999
108
0
0
SG
I have a procedure Check_Suspend and it calls another
procedure Check_Limit.

Check_Limit procedure is basically just a select statement
base on its 'IN parameter' to add the total of a field 'sum(a).

How can Check_Suspend
1. call Check_Limit
2. get the value of sum(a) from Check_Limit?
 
Check_limit should be a function, not a procedure. It should return the value of sum(a).
 
Or it could be a procedure with an output parameter. Generally if the module will return only one value, it is good practice to make it a function. If you need to return more than one value, then a procedure has to be used.

OK, to call a function just put something like this in your code:
Code:
.
.
.
   v_sum := check_limit (v_input);
.
.
.
 
how do I declare funciton inside a package?
I'm having trouble declaring it inside a package..


==
create or replace package my_pkg
as

procedure Check_Suspend (
p_stuID IN tableA.stuID%type);

function Check_Limit (
p_stuID IN tableA.stuID%type);

end my_pkg;

create or replace package body my_pkg
as

-- Check_Limit
function Get_Points (
p_stuID IN tableA.stuID%type)
AS
RETURN number IS

v_points number;
v_stuID tableA.stuID%type := LOWER(p_stuID);
BEGIN

...

return v_points;
end Get_Points;

end my_pkg;
 
function Check_Limit (
p_stuID IN tableA.stuID%type return number
is
...


return <value>;
end;
 
Sorry, missing bracket:

function Check_Limit (p_stuID IN tableA.stuID%type)
return number
is
...


return v_points;
end;
 
ok, I have it as follows but still get error..

==
46/43 PLS-00103: Encountered the symbol &quot;;&quot; when expecting one of the
following:
return


Warning: Package Body created with compilation errors.
====


My code is as follows..

==
create or replace package my_pkg
as

procedure Check_Suspend (
p_stuID IN tableA.stuID%type);

function Check_Limit (
p_stuID IN tableA.stuID%type);

end my_pkg;

create or replace package body my_pkg
as


function Check_Limit (
p_stuID IN tableA.stuID%type)
RETURN number IS

v_points number;
v_stuID tableA.stuID%type := LOWER(p_stuID);
BEGIN

...

return v_points;
end Check_Limit;

end my_pkg;
 
Your forward declaration needs a return clause as well:

function Check_Limit (
p_stuID IN tableA.stuID%type) return number;


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top