存储过程掠影-20201020

困扰许久的玩意,终于搞定了。哈哈
 
 
以下为源代码:
 
#该存储过程用意简单 即造测试数据。
DELIMITER $$
 
USE `sakila`$$
 
DROP PROCEDURE IF EXISTS `test_insertdata`$$
 
CREATE DEFINER=`root`@`%` PROCEDURE `test_insertdata`(IN `loopcount` INT)
    COMMENT '123'
BEGIN     
DECLARE v_uuid  VARCHAR(50);
WHILE loopcount>0 DO    
     INSERT INTO test_order (user_id,order_id,order_status,create_date) VALUES (RAND()*1000,id,RAND()*10,DATE_ADD(NOW(), INTERVAL - RAND()*20000 HOUR));
     INSERT INTO test_orderdetail(order_id,product_name,cnt,create_date) VALUES (RAND()*100000,v_uuid,RAND()*10,DATE_ADD(NOW(), INTERVAL - RAND()*20000 HOUR));
  
SET v_uuid = UUID()  ;       
SET loopcount = loopcount -1    ;
END WHILE;
 
    END$$
 
DELIMITER ;
 
#调用该存储过程,5000000 为传入参数
mysql> CALL test_insertdata(5000000);
 
#该存储过程执行完之后,确认数据
mysql> select count(1) from test_order;
+----------+
| count(1) |
+----------+
|  5000000 |
+----------+
1 row in set (0.97 sec)
 
mysql> select count(1) from test_orderdetail;
+----------+
| count(1) |
+----------+
|  5000100 |
+----------+
1 row in set (1.14 sec)
 
哈哈
创建时间:2021-12-22 10:16
浏览量:0