The syntax for the create function command is more complicated than the syntax for the create procedure command. At a high level, the syntax is
create [or replace] function [schema .] function
[( argument [ in | out | in out ] [nocopy] datatype
[, argument [ in | out | in out ] [nocopy] datatype]...
)]
return datatype
[{ invoker_rights_clause | deterministic | parallel_enable_clause }
[ invoker_rights_clause | deterministic | parallel_enable_clause ]...
]
{ { aggregate | pipelined } using [schema .] implementation_type
| [pipelined] { is | as } { pl/sql_function_body | call_spec }};
Both the header and the body of the function are created by this command. The return keyword specifies the datatype of the function's return value.
This can be any valid PL/SQL datatype. Every function must have a return clause, since the function must, by definition, return a value to the calling environment.
The following example shows a function named OVERDUE_CHARGES, which returns the overdue book charges by person, based on calculations against the BOOKSHELF_CHECKOUT table.
The input is the name of the person, while the output is the balance for that person.