Procedure and function parameters v15
An important aspect of using procedures and functions is the capability to pass data from the calling program to the procedure or function and to receive data back from the procedure or function. You do this by using parameters.
Declare parameters in the procedure or function definition, and enclose them in parentheses following the procedure or function name. Parameters declared in the procedure or function definition are known as formal parameters. When you invoke the procedure or function, the calling program supplies the actual data to use in the called program’s processing as well as the variables that receive the results of the called program’s processing. The data and variables supplied by the calling program when the procedure or function is called are referred to as the actual parameters.
The following is the general format of a formal parameter declaration.
name
is an identifier assigned to the formal parameter.- Whether a parameter is
IN
,OUT
, orIN OUT
is referred to as the parameter’s mode. If specified,IN
defines the parameter for receiving input data into the procedure or function. AnIN
parameter can also be initialized to a default value. If specified,OUT
defines the parameter for returning data from the procedure or function. If specified,IN OUT
allows the parameter to be used for both input and output. If all ofIN
,OUT
, andIN OUT
are omitted, then the parameter acts as if it were defined asIN
by default. data_type
defines the data type of the parameter.value
is a default value assigned to anIN
parameter in the called program if you don't specify an actual parameter in the call.
This example shows a procedure that takes parameters:
In this example, p_deptno
is an IN
formal parameter, p_empno
and p_ename
are IN OUT
formal parameters, and p_job, p_hiredate
and p_sal
are OUT
formal parameters.
Note
In the example, no maximum length was specified on the VARCHAR2
parameters and no precision and scale were specified on the NUMBER
parameters. It's illegal to specify a length, precision, scale, or other constraints on parameter declarations. These constraints are inherited from the actual parameters that are used when the procedure or function is called.
The emp_query
procedure can be called by another program, passing it the actual parameters. This example is another SPL program that calls emp_query
.
In this example, v_deptno
, v_empno
, v_ename
, v_job
, v_hiredate
, and v_sal
are the actual parameters.
The output from the example is:
positional_vs_named_parameter_notation parameter_modes using_default_values_in_parameters