PL/SQL block to obtain factorial of a number

Q. Write a Pl/SQL block to obtain factorial of a number.

Answer:

Factorial number: The factorial of a non-negative integer 'n' is denoted by n!. It is the product of all positive integers less then or equal to 'n'.

For example:
3! = 3*2*1 = 6  

Declare  
num   number:= #  
fact number:= 1;  
temp number;  
begin  
  temp := num;  
   while (num > 0)
loop
    fact := fact * num;  
    num   := num - 1;  
end loop;
  Dbms_Output.Put_line('factorial of ' || temp ||  '  is ' || fact);  
end;
/


The above program will compute the factorial of a given number.

Output:

factorial