FACTORIAL OF THE GIVEN NUMBER IN RECURSIVE FUNCTION USING PL/SQL FUNCTION AND PROCEDURE

Algorithm for recursive function:
Accept the value of n in the function FACT through parameters.
If n=1 return 1otherwise return n fact(n-1).
Stop the program.
Algorithm for main function :
Get the value of n, factorial to be found.
Call the function fact with parameters.
Display the factorial of a given number.
Stop the program.
PROGRAM:
Function :
SQL> create or replace function fact(n number)
2 return number is
3 begin
4 if n=1 then
5 return 1;
6 else
7 return n*fact(n-1);
8 end if;
9 end fact;
10 /


Function created.
Main program:
SQL> declare
2 n number(4):=&n;
3 n1 number(8);
4 begin
5 n1:=fact(n);
6 dbms_output.put_line('factorial of'n'is'n1);
7 end;
8 /