3

I want to call a function inside a procedure and get it's value so I can use within the procedure but I have no idea how to do that ?? Any ideas ?? My function is the following one , this function returns a collection of employees' ids whose salary out of the max or min salary , I want to use this value in a procedure to update the salaries of those employees to the minimum salary ??

Lara Dax
  • 131
  • 2
  • 5
  • 10
  • Try to solve this with an UPDATE rather than a mishmash of stored procedures. When you say "this function returns a collection of employee's ids" that IS a set, which is best obtained by an SELECT statement. – Michael O'Neill Oct 03 '13 at 17:53

3 Answers3

5
create or replace procedure P
    a_variable_name number;
begin
    a_variable := a_function('a parameter');
end;
/
Shannon Severance
  • 18,025
  • 3
  • 46
  • 67
1

Here is the sample code that will help you calling a function from a procedure.

    create or replace FUNCTION ADD_TEN(P_IN VARCHAR2) RETURN VARCHAR2
    AS
    L_RESULT VARCHAR2(4000);
    BEGIN
    L_RESULT:=P_IN+10;
    RETURN L_RESULT;
    END;



    create or replace PROCEDURE CALL_FUNCTON(P_IN VARCHAR2)
        AS
        L_FINAL_RESULT VARCHAR2(4000);
        BEGIN
        L_FINAL_RESULT:=ADD_TEN(P_IN);
        DBMS_OUTPUT.PUT_LINE(L_FINAL_RESULT);
        -- USE L_FINAL_RESULT IN YOUR BUSINESS LOGIC
        END;

EXECUTE CALL_FUNCTON(5);
Ankit Mongia
  • 200
  • 2
  • 11
0
declare

procedure my_proc;

function my_func return number is

begin

my_proc;

return 3;

end my_func;

procedure my_proc is

begin

dbms_output.put_line('22');

end my_proc;

begin

dbms_output.put_line(my_func);

end;
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Ashish sinha
  • 148
  • 2
  • 9