Recent Posts

Wednesday, 27 July 2016

Functions in PL/SQL


1. Function is a self contained block which performs specific task.
2. The main advantage of function is code reusability.
3. Function returns one value.
4. 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
2Body 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
P) 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)

Next Tutorial  Packages in PL/SQL

Previous Tutorial  Sub Programs in PL/SQL

No comments:

Post a Comment