다음 쿼리의 도움으로 5개의 난수를 생성하는 저장 프로시저를 만들 수 있습니다.
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 -> // Query OK, 0 rows affected (0.16 sec) Query OK, 0 rows affected (0.16 sec)
이제 결과를 얻기 위해 프로시저를 호출하십시오 -
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) Query OK, 0 rows affected (0.05 sec)