oracle 如何在 plsql 的过程中调用函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16704327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:03:40  来源:igfitidea点击:

How can I call a function inside a procedure in plsql

oraclefunctionstored-proceduresplsqldeveloper

提问by Lara Dax

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

我想在过程中调用一个函数并获取它的值,这样我就可以在过程中使用,但我不知道该怎么做??有任何想法吗 ??我的函数如下,该函数返回工资超出最大或最小工资的员工 id 的集合,我想在程序中使用此值将这些员工的工资更新为最低工资??

回答by Shannon Severance

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

回答by Ankit Mongia

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

回答by Ashish sinha

declare

procedure my_proc;

function my_func return number is

函数 my_func 返回数是

begin

my_proc;

return 3;

end my_func;

procedure my_proc is

过程 my_proc 是

begin

dbms_output.put_line('22');

end my_proc;

begin

dbms_output.put_line(my_func);

end;