is a subprogram that can take parameters and return a single value. A function has two parts:
- the specification and
- the body.
The specification (spec for short) begins with the keyword FUNCTION and ends with the RETURN clause, which specifies the datatype of the return value.
are optional and functions that take no parameters are written without parentheses. The function body begins with the keyword IS (or AS) and ends with the keyword END followed by an optional function name.
The function body has three parts:
- an optional declarative part,
- an executable part, and
- an optional exception-handling part.
The declarative part
contains declarations of
- exceptions, and
These items are local and cease to exist when you exit the function. The executable part contains statements that assign values, control execution, and manipulate data.
The exception-handling part contains handlers that deal with exceptions raised during execution.
Note that the function declaration in a PL/SQL block or package is not the same as creating a function in SQL.