A parameter is a list of optional parameters that you create to transmit information into the procedure and send information out of the procedure to the calling application. The argument is another name for a parameter. When you define a parameter, you also describe how it may be used. There are two types of parameters or arguments, i.e., Actual Parameters and Formal Parameters.
What are the Actual Parameters?
The arguments given in a function call are referred to as actual parameters. The calling function defines these parameters. These are the variables or expressions that are mentioned in a subprogram call’s argument list. It is not necessary to mention the data type in the actual argument.
Example:
// A and B NUMBER ARE ACTUAL PARAMETERS
SQL> CREATE OR REPLACE FUNCTION FUNC1(A NUMBER,
B NUMBER)
2 RETURN NUMBER IS
3 R NUMBER;
4 BEGIN
5 R:=A+B;
6 RETURN(R);
7 END;
8 /
FUNCTION CREATED.
SQL>|
What are Formal Parameters?
These are the variables or expressions that are mentioned in a subprogram specification’s parameter list. The receiving value’s data type must be specified. Formal arguments have a scope that is limited to the function declaration in which they are employed.
Example:
SQL> DECLARE
2 N1 NUMBER:=1;
3 N2 NUMBER:=2;
4 S NUMBER;
5 BEGIN
6 S:=FUNC1(N1, N2);
7 DBMS_OUTOUT.PUT_LINE(‘RESULT IS: ‘||S);
8 END;
9 /
OUTPUT: RESULT IS: 3
PL/SQL PROCEDURE SUCCESSFULLY COMPLETED.
SQL>|
Actual and Formal Parameters: Difference
Actual Parameters | Formal Parameters |
When a function is called, the values (expressions) given in the function call are referred to as the arguments or actual parameters | Formal parameters are those used in function definition statements that contain data types at the time of declaration |
These are the variables or expressions that are mentioned in a subprogram call’s argument list | These are the variables or expressions that are mentioned in a subprogram specification’s parameter list |
The parameters that are in the calling subprogram are the actual parameters | Formal parameters are the parameters found in a subprogram |
It is not necessary to mention the data type in the actual argument | The receiving value’s data type must be specified |
The parameters specified in a function call are referred to as real parameters | Formal parameters are the parameters that are written in the function definition |
Parameters can be either constant values or variable names | Formal parameters can be thought of as local variables of a function that are utilised in the function header |
Formal and Actual Parameters: Summary
Using Functions is a valuable programming idea. Functions aid in reducing code length and complexity. It also makes testing and debugging easier and enhances code maintainability. Some functions may not need inputs, whilst others may. Data can be sent to the functions as inputs. They are referred to as parameters. Actual Parameters and Formal Parameters are two often used concepts in relation to functions. Actual Parameters vary from Formal Parameters in that Actual Parameters are values supplied to the function when it is invoked, whereas Formal Parameters are variables declared by the function that get values when the function is called.
Conclusion
When we think of the Oracle database, the two notions that spring to mind are actual parameters and formal parameters. Both of these terms are associated with programming and SQL.The actual arguments are those stated in the calling function. Formal parameters, on the other hand, are those that are defined in the called function.