Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 The Oracle PL/SQL FUNCTION Statement      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.

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      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 276 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?