Quick Search:
 
 The Oracle PL/SQL FUNCTION Statement      [Return To Index] Jump to:  

Term: FUNCTION

Definition:
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.

Example Syntax:

CREATE [OR REPLACE] FUNCTION [NAME][PARAMETER LIST] RETURN [DATA TYPE]
[IS | AS]
...
BEGIN
STATEMENT 1;
STATEMENT 2;
...
RETURN [VALUE]
STATEMENT N;
END;


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.

Example Usage:

CREATE OR REPLACE FUNCTION F_AVG_SALARY RETURN NUMBER IS
L_AVG NUMBER;
BEGIN
SELECT AVG(SALARY)
INTO L_MAX
FROM EMP;
RETURN L_AVG;
END;

Function Created.



Related Links:

Related Code Snippets:
 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org