MySQL基础:存储过程(利用存储过程生成随机数据)

    xiaoxiao2022-07-03  111

    1.创建存储过程 右键函数,新建函数 2. 创建函数或者存储过程 填入参数 3. 填写存储过程代码

    随机往aws_action表中插入数据

    BEGIN DECLARE i int UNSIGNED; DECLARE t int UNSIGNED; set i=1; set t=1529370782; while i<=num DO if(iP=0) then set t=t+FLOOR(1+RAND()*18); ELSE set t=t+FLOOR(1+RAND()*10000); end if; insert into aws_action(item_id,user_id,start_time) values(FLOOR(11000+RAND()*60000),FLOOR(1+RAND()*17),t); set i = i + 1; end while; END 原始SQL语句 DROP PROCEDURE IF EXISTS `insertaction`; CREATE DEFINER = `root`@`%` PROCEDURE `insertaction`(IN `num` int) BEGIN DECLARE i int UNSIGNED; DECLARE t int UNSIGNED; set i=1; set t=1529370782; while i<=num DO if(iP=0) then set t=t+FLOOR(1+RAND()*18); ELSE set t=t+FLOOR(1+RAND()*10000); end if; insert into aws_action(item_id,user_id,start_time) values(FLOOR(11000+RAND()*60000),FLOOR(1+RAND()*17),t); set i = i + 1; end while; END;
    最新回复(0)