In Oracle PL/SQL, a FUNCTION is a named PL/SQL subprogram. A function always returns a single value upon its call. It works similarly to stored procedures, with minor syntactical differences and objectives. A function's main purpose is to perform a computation based on a given set of logical conditions. It must return a single value to the host or calling environment. Like procedures, functions contain header and executable sections, with a logical RETURN clause.
CREATE [OR REPLACE] FUNCTION [NAME][PARAMETER LIST] RETURN [DATA TYPE]
[IS | AS]
Functions can be stored in the database itself, and are also referred to as stored functions. They permit the reuse of logic, allow for code flexibility, and enable modularity. Unlike procedures, stored functions can also be used in SQL statements, if they obey specific rules to avoid database changes.
CREATE OR REPLACE FUNCTION F_AVG_SALARY RETURN NUMBER IS
Related Code Snippets: