In this section, we will see how to find factorial of a number using the PL/SQL. In PL/SQL code, some group of commands is arranged within a block of the related declaration of statements.
Factorial of a number is basically multiplication of all integers from 1 to n, where n is the given number. So n! = n * (n – 1) * (n – 2) * … * 2 * 1.
DECLARE fact number :=1; n number := &1; BEGIN while n > 0 loop fact:=n*fact; n:=n-1; end loop; dbms_output.put_line(fact); END;
Consider 5 has given 120