What is the difference between function and procedure in PL/SQL?

后端 未结 7 1052
日久生厌
日久生厌 2020-11-27 14:30

What is the difference between function and procedure in PL/SQL ?

7条回答
  •  情话喂你
    2020-11-27 14:47

    A procedure does not have a return value, whereas a function has.

    Example:

    CREATE OR REPLACE PROCEDURE my_proc
       (p_name IN VARCHAR2 := 'John') as begin ... end
    
    CREATE OR REPLACE FUNCTION my_func
       (p_name IN VARCHAR2 := 'John') return varchar2 as begin ... end
    

    Notice how the function has a return clause between the parameter list and the "as" keyword. This means that it is expected to have the last statement inside the body of the function read something like:

    return(my_varchar2_local_variable);
    

    Where my_varchar2_local_variable is some varchar2 that should be returned by that function.

提交回复
热议问题