FIND THE FACTORIAL OF ANY NUMBER USING FUNCTION:
CREATE OR REPLACE FUNCTION FACTORIAL (NUM POSITIVE)
RETURN INTEGER IS
BEGIN
IF NUM = 1 THEN -- Terminating condition
RETURN 1;
ELSE
RETURN NUM * FACTORIAL(NUM - 1) ; -- Recursive call
END IF;
END FACTORIAL;
OUTPUT: Fuction created.
Call the function "FACTORIAL" in Sql Statement
SELECT FACTORIAL(1), FACTORIAL(2), FACTORIAL(3), FACTORIAL(4), FACTORIAL(5),FACTORIAL(6),FACTORIAL(7),
FACTORIAL(8),FACTORIAL(9),FACTORIAL(10) FROM dual;
No comments:
Post a Comment