它可以在以下查詢的幫助下創建-
mysql> Delimiter // mysql> CREATE PROCEDURE fact(IN x INT) -> BEGIN -> DECLARE result INT; -> DECLARE i INT; -> 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// Query OK, 0 rows affected (0.17 sec)
現在,當透過傳遞我們想要獲取階乘作為參數的值來呼叫此過程時-
mysql> Delimiter ; mysql> CALL Fact(5); +--------+-----------+ | Number | Factorial | +--------+-----------+ | 5 | 120 | +--------+-----------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> CALL Fact(6); +--------+-----------+ | Number | Factorial | +--------+-----------+ | 6 | 720 | +--------+-----------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
以上是創建一個程式來找出數字的階乘?的詳細內容。更多資訊請關注PHP中文網其他相關文章!