Parameter modes (PL/SQL)
PL/SQL procedure parameters can have one of three possible modes: IN, OUT, or IN OUT. PL/SQL function parameters can only be IN.
- An IN formal parameter is initialized to the actual parameter with which it was called, unless it was explicitly initialized with a default value. The IN parameter can be referenced within the called program; however, the called program cannot assign a new value to the IN parameter. After control returns to the calling program, the actual parameter always contains the value to which it was set prior to the call.
- An OUT formal parameter is initialized to the actual parameter with which it was called. The called program can reference and assign new values to the formal parameter. If the called program terminates without an exception, the actual parameter takes on the value to which the formal parameter was last set. If a handled exception occurs, the actual parameter takes on the last value to which the formal parameter was set. If an unhandled exception occurs, the value of the actual parameter remains what it was prior to the call.
- Like an IN parameter, an IN OUT formal parameter is initialized to the actual parameter with which it was called. Like an OUT parameter, an IN OUT formal parameter is modifiable by the called program, and the last value of the formal parameter is passed to the calling program's actual parameter if the called program terminates without an exception. If a handled exception occurs, the actual parameter takes on the last value to which the formal parameter was set. If an unhandled exception occurs, the value of the actual parameter remains what it was prior to the call.
Table 1 summarizes
this behavior.
Mode property | IN | IN OUT | OUT |
---|---|---|---|
Formal parameter initialized to: | Actual parameter value | Actual parameter value | Actual parameter value |
Formal parameter modifiable by the called program? | No | Yes | Yes |
After normal termination of the called program, actual parameter contains: | Original actual parameter value prior to the call | Last value of the formal parameter | Last value of the formal parameter |
After a handled exception in the called program, actual parameter contains: | Original actual parameter value prior to the call | Last value of the formal parameter | Last value of the formal parameter |
After an unhandled exception in the called program, actual parameter contains: | Original actual parameter value prior to the call | Original actual parameter value prior to the call | Original actual parameter value prior to the call |