SQL>
SQL> set serveroutput on
SQL> set echo on
SQL>
SQL> CREATE OR REPLACE FUNCTION Factorial(p_MyNum INTEGER) RETURN NUMBER AS
2 BEGIN
3 IF p_MyNum = 1 THEN -- Checking for last value to process of n-1
4 RETURN 1;
5 ELSE
6 RETURN(p_MyNum * Factorial(p_MyNum-1)); -- Recursive
7 END IF;
8 END;
9 /
Function created.
SQL>
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE(factorial(10));
3 END;
4 /
3628800
PL/SQL procedure successfully completed.