Header Ads

Header ADS

PL/SQL Program to Find Factorial of a Number

PL/SQL Program to Find Factorial of a Number

Topic Introduction: In this tutorial, we will show a PL/SQL Program to Find the Factorial of a Number which is a common question in interviews as an Oracle Developer. Here Calculation of the factorial of 6. 6!=6*5*4*3*2*1=720. The factorial of 6 is equal to 720. And factorial of 7. 7!=7*6*5*4*3*2*1=5040. The factorial of 7 is equal to 5040.
Now we will make a function to get the factorial of a number.


Example:

CREATE OR REPLACE FUNCTION FUN_FACTORIAL (P_FACNO NUMBER)
    RETURN NUMBER
IS
    V_FACNO   NUMBER := 1;
BEGIN
    FOR i IN 1 .. P_FACNO
    LOOP
        V_FACNO := V_FACNO * i;
    END LOOP;

    RETURN V_FACNO;
EXCEPTION
    WHEN NO_DATA_FOUND THEN RETURN NULL;
    WHEN OTHERS THEN RETURN NULL;
END;
/

Check Function:

SELECT FUN_FACTORIAL (6) FROM DUAL;










***Thanks for visiting my blog. My Youtube channel is Oracle School BD. You can visit here to see video tutorials.*** 

No comments

Theme images by Deejpilot. Powered by Blogger.