Oracle® Database PL/SQL User's Guide and Reference 10g Release 2 (10.2) Part Number B14261-01 |
|
|
PDF · Mobi · ePub |
The RETURN
statement immediately completes the execution of a subprogram and returns control to the caller. Execution resumes with the statement following the subprogram call. In a function, the RETURN
statement also sets the function identifier to the return value. See "Using the RETURN Statement".
return statement ::=
Keyword and Parameter Description
expression
A combination of variables, constants, literals, operators, and function calls. The simplest expression consists of a single variable. When the RETURN
statement is executed, the value of expression
is assigned to the function identifier.
The RETURN
statement is different than the RETURN
clause in a function spec, which specifies the datatype of the return value.
A subprogram can contain several RETURN
statements. Executing any of them completes the subprogram immediately. The RETURN
statement might not be positioned as the last statement in the subprogram. The RETURN
statement can be used in an anonymous block to exit the block and all enclosing blocks, but the RETURN
statement cannot contain an expression.
In procedures, a RETURN
statement cannot contain an expression. The statement just returns control to the caller before the normal end of the procedure is reached. In functions, a RETURN
statement must contain an expression, which is evaluated when the RETURN
statement is executed. The resulting value is assigned to the function identifier. In functions, there must be at least one execution path that leads to a RETURN
statement. Otherwise, PL/SQL raises an exception at run time.
For examples, see the following: