📜  PL/SQL 中实际参数和形式参数的区别

📅  最后修改于: 2021-09-11 03:33:01             🧑  作者: Mango

参数是一个可选的参数列表,您可以定义这些参数将信息传递到过程中并将信息从过程中发送回调用程序。参数也称为参数。定义参数时,还指定了它的使用方式。参数或参数有三种不同的模式。

1. 实际参数:
在函数调用中传递的参数称为实际参数。这些参数在调用函数中定义。这些是在子程序调用的参数列表中引用的变量或表达式。实参中无需指定数据类型。

例子 :

// X and Y NUMBER ARE ACTUAL PARAMETERS
SQL> CREATE OR REPLACE FUNCTION FUNC1(X NUMBER, 
                                         Y NUMBER) 
2    RETURN NUMBER IS
3    R NUMBER;
4    BEGIN
5    R:=X+Y;
6    RETURN(R);
7    END;
8    /
FUNCTION CREATED.

SQL>|

2. 形式参数:
这些是在子程序规范的参数列表中引用的变量或表达式。必须定义接收值的数据类型。形式参数的范围是使用它们的函数定义的局部范围。

例子 :

SQL> DECLARE
2    N1 NUMBER:=10;
3    N2 NUMBER:=20;
4    S NUMBER;
5    BEGIN
6    S:=FUNC1(N1, N2);
7    DBMS_OUTOUT.PUT_LINE('RESULT IS: '||S);
8    END;
9    /

OUTPUT: RESULT IS: 30
PL/SQL PROCEDURE SUCCESSFULLY COMPLETED.
SQL>|

实际参数和形式参数的区别:

Actual Parameters Formal Parameters
When a function is called, the values (expressions) that are passed in the function call are called the arguments or actual parameters. The parameter used in function definition statement which contain data type on its time of declaration is called formal parameter.
These are the variables or expressions referenced in the parameter list of a subprogram call. These are the variables or expressions referenced in the parameter list of a subprogram specification.
Actual Parameters are the parameters which are in calling subprogram. Formal Parameters are the parameters which are in called subprogram.
There is no need to specify datatype in actual parameter. The datatype of the receiving value must be defined.
The parameters are written in function call are known as actual parameters. The parameters are written in function definition are known as formal parameters.
Actual Parameters can be constant values or variable names. Formal Parameters can be treated as local variables of a function in which they are used in the function header.