创建一个生成五个随机数的MySQL存储过程?
借助以下查询,我们可以创建一个存储过程来生成五个随机数-
mysql> DELIMITER //mysql> DROP PROCEDURE IF EXISTS RandomNumbers;
-> CREATE PROCEDURE RandomNumbers() -> BEGIN
-> SET @i = 0;
-> REPEAT
-> SELECT RAND() AS 'Random Number';
-> SET @i = @i + 1;
-> UNTIL @i >=5 END REPEAT;
-> END
-> //
现在,调用该过程以获取结果-
mysql> DELIMITER ;mysql> CALL RandomNumbers();
+---------------------+
| Random Number |
+---------------------+
| 0.25968261739209536 |
+---------------------+
1 row in set (0.00 sec)
+--------------------+
| Random Number |
+--------------------+
| 0.1659662734400167 |
+--------------------+
1 row in set (0.01 sec)
+---------------------+
| Random Number |
+---------------------+
| 0.05078354575744229 |
+---------------------+
1 row in set (0.01 sec)
+--------------------+
| Random Number |
+--------------------+
| 0.7560189392008064 |
+--------------------+
1 row in set (0.04 sec)
+------------------+
| Random Number |
+------------------+
| 0.62774408946535 |
+------------------+
1 row in set (0.04 sec)
以上是 创建一个生成五个随机数的MySQL存储过程? 的全部内容, 来源链接: utcz.com/z/326706.html