Lara Dax
Lara Dax

Reputation: 151

How can I call a function inside a procedure in plsql

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 ??

Upvotes: 4

Views: 52874

Answers (3)

Ankit Mongia
Ankit Mongia

Reputation: 210

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

Upvotes: 1

Ashish sinha
Ashish sinha

Reputation: 148

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;

Upvotes: 0

Shannon Severance
Shannon Severance

Reputation: 18410

create or replace procedure P
    a_variable_name number;
begin
    a_variable := a_function('a parameter');
end;
/

Upvotes: 6

Related Questions