Open In App

Difference between Actual and Formal Parameters in PL/SQL

Last Updated : 23 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

A parameter is an optional list of parameters that you define both pass information into the procedure and send information out of procedure back to the calling program. Parameter is also known as argument. When you define a parameter, you also specify the way in which it can be used. There are three different modes of parameter or argument.

1. Actual Parameters :
The arguments that are passed in a function call are called actual arguments. These arguments are defined in the calling function. These are the variables or expressions referenced in the parameter list of a subprogram call. There is no need to specify datatype in actual parameter.

Example :

// 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. Formal Parameters :
These are the variables or expressions referenced in the parameter list of a subprogram specification. The datatype of the receiving value must be defined. The scope of formal arguments is local to the function definition in which they are used.

Example :

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



Difference between Actual and Formal Parameters :

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads