Functions

Functions
  • Function is a self contained block which performs specific task.
  • The main advantage of function is code re-usability.
  • Function returns one value.
  • Functions are classified into two types those are
System Defined Function

A function which is defined by the system along with the software those functions can be called as system defined functions.

E.g

Length()

User Defined Functions

A function which is defined by the user manually or programmatically those functions can be called as user defined functions.

E.g

 Addd()

Functions are used to estimate or calculate any value. Function contains two sections.

  1. Declaration of the function
  2. Body of the function.

Declaration of the function always starts with a keyword called create and ends with return statement where as body of the function start with a keyword called is and ends with end statement.

Syntax

CREATE OR REPLACE FUNCTION (Function Name)
List of formal parameters)
RETURN TYPE
   IS/AS
BEGIN
   STATEMENT1
       ‘
       ‘
       ‘
   STATEMENT N;
   RETURN VARIABLE
END

Write a function to add two numbers.

create or replace function kin(a in number, b in number)
return number
   is
   c number;
begin
   C:=a+b;
   return c;
end;

// Execution Process
var x number
exec :x:=kin(10,20)
Functions
Scroll to top