Oracle Database の以下の PL/SQL コードを
standard_price := DBMS_RANDOM.VALUE(30,50);
MySQL ではこう書き換えると同じことができる。
select round( rand() * 20 + 30 ) into var_standard_price;
実際にプロシージャを作成して実行してみるとこんな感じ。
5.6.10-log awsuser: [mydb] 09:32> delimiter // 5.6.10-log awsuser: [mydb] 09:32> create procedure rand_test() -> begin -> declare var_standard_price decimal (6, 2); -> select round( rand() * 20 + 30 ) into var_standard_price; -> select var_standard_price; -> end -> // Query OK, 0 rows affected (0.02 sec) 5.6.10-log awsuser: [mydb] 09:32> delimiter ; 5.6.10-log awsuser: [mydb] 09:33> call rand_test(); +--------------------+ | var_standard_price | +--------------------+ | 35.00 | +--------------------+ 1 row in set (0.02 sec) Query OK, 0 rows affected (0.02 sec) 5.6.10-log awsuser: [mydb] 09:33> call rand_test(); +--------------------+ | var_standard_price | +--------------------+ | 45.00 | +--------------------+ 1 row in set (0.01 sec) Query OK, 0 rows affected (0.01 sec)