mysql factorial stored procedure example
snippet in sql

mysql factorial stored procedure example

user7803

delimiter //
CREATE PROCEDURE fact(IN x BIGINT)
BEGIN
DECLARE result BIGINT;
DECLARE i BIGINT;
SET result = 1;
SET i = 1;
WHILE i <= x DO
SET result = result * i;
SET i = i + 1;
END WHILE;
SELECT x AS Number, result as Factorial;
END//
delimiter ;