1delimiter //
2CREATE PROCEDURE fact(IN x BIGINT)
3BEGIN
4DECLARE result BIGINT;
5DECLARE i BIGINT;
6SET result = 1;
7SET i = 1;
8WHILE i <= x DO
9SET result = result * i;
10SET i = i + 1;
11END WHILE;
12SELECT x AS Number, result as Factorial;
13END//
14delimiter ;