Showing posts with label pl/sql function. Show all posts
Showing posts with label pl/sql function. Show all posts

Friday, November 18, 2011

Function Example in PL/SQL Oracle

It is a sample pl/sql oracle example which have a function cube1 and a program. When a function calls accepted number(no) from user is passed as a argument and output of cube1 function is return value to variable(res).


Aim - PL/SQL program to accept a number from user and display its cube(num^3) value using function.


Function:-
First Execute Function PL/SQL block
create or replace function cube1(no in number) return number IS result number(8);
begin
  result:=(no*no*no);
  return result;
exception
  when no_data_found then
  return 'error';
end;


Program: -
Second Execute PL/SQL Program
declare
 no number(5);
 res number(10);
begin
  no:=&no;
  res:=cube1(no);
  dbms_output.put_line('Cube of ' || no || ' is '|| res);
end;


Output: -
Enter value for no: 6
old 5: no:=&no;
new 5: no:=6;
Cube of 6 is 216