0% found this document useful (0 votes)
47 views1 page

MySQL Function to Calculate Factorial

This stored procedure calculates the factorial of a given integer number. It declares a variable to store the factorial, initializes it to 1, then uses a WHILE loop to iteratively multiply the factorial by the input number down from the given number to 1. It returns the final calculated factorial.

Uploaded by

sdfsafd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views1 page

MySQL Function to Calculate Factorial

This stored procedure calculates the factorial of a given integer number. It declares a variable to store the factorial, initializes it to 1, then uses a WHILE loop to iteratively multiply the factorial by the input number down from the given number to 1. It returns the final calculated factorial.

Uploaded by

sdfsafd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

DELIMITER //

CREATE FUNCTION calcular_factorial(n INT)


RETURNS INT
BEGIN
DECLARE factorial INT;
SET factorial = 1;

WHILE n > 0 DO
SET factorial = factorial * n;
SET n = n - 1;
END WHILE;

RETURN factorial;
END //
DELIMITER ;

You might also like