mysql 批量插入脚本详解

delimiter $$
drop procedure if exists insert_record;    ##如果脚本insert_record存在就删除。
create procedure insert_record(in max_num int(10)) ##创建一个全局常量,并给它一个范围
begin
    declare chars_str varchar(52) default 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';  ##创建局部常量,这里选择英文用于,随机截取。
    declare user_name varchar(255) default '兰亭临帖行书如行云流水月下门推心细如你脚步碎忙不迭千年碑易拓却难拓你的美真迹绝真心能给谁牧笛横吹黄酒小菜有几碟夕阳余晖如你的羞怯似醉摹本易写悬笔一绝那岸边浪千叠情字何解怎落笔都不对而我独缺你一生的了解弹指岁月倾城顷刻间烟灭青石板街回眸一笑你婉约恨了没你摇头轻叹谁让你蹙着眉而深闺徒留胭脂味人雁南飞转身一瞥你噙泪掬一把月手揽回忆怎么睡又怎么会心事密缝绣花鞋针针怨怼若花怨蝶你会怨着谁无关风月我题序等你回悬笔一绝那岸边浪千叠情字何解怎落笔都不对而我独缺你一生的了解';  ##创建局部常量,这里选择中文用于,随机截取人物名称。
    declare i int default 0; ##创建局部常量,这里默认0,用于遍历。
    ## set autocommit=0;
    repeat
        set i=i+1;  ##开始循环
        insert into user_operation_record (department_id,department,platform,group_id,group_name,manager_code,manager,group_leader_code,
                                           group_leader,user_code,user,operator_time,domain_name,belong_erp,url,access_duration,inactive_duration,operation_function,
                                           operation_log,create_by,create_time) values(

                                                                                                  round(rand() * 10000, 0),
                                                                                                     CONCAT(substring(user_name,floor(1+rand()*52),2),'部'),
                                                                                                      substring(chars_str,floor(1+rand()*52),3),
                                                                                                      round(rand() * 1000, 0),
                                                                                                      CONCAT(substring(user_name,floor(1+rand()*52),2),'组'),
                                                                                                      round(rand() * 1000, 0)+'',
                                                                                                      CONCAT(substring(user_name,floor(1+rand()*52),2),'主管'),
                                                                                                      round(rand() * 1000, 0)+'',
                                                                                                      CONCAT(substring(user_name,floor(1+rand()*52),2),'组长'),
                                                                                                      round(rand() * 1000, 0)+'',
                                                                                                      CONCAT(substring(user_name,floor(1+rand()*52),2),'用户'),
                                                                                                      DATE_ADD('2023-02-06 00:00:00',  INTERVAL  FLOOR(1 + (RAND() * 10800))   HOUR ),
                                                                                                      'https://www.baidu.com/',
                                                                                                      'erp系统',
                                                                                                      'https://www.baidu.com/',
                                                                                                      rand(),
                                                                                                      rand(),
                                                                                                      '查询',
                                                                                                      null,
                                                                                                      CONCAT(substring(user_name,floor(1+rand()*52),2),'用户'),
                                                                                                      DATE_ADD('2023-02-06 00:00:00',  INTERVAL  FLOOR(1 + (RAND() * 10800))   HOUR )
                                                                          );
    until i=max_num  ##停止循环条件
        end repeat; 
    commit; ##事务 同时提交
end $$



DELIMITER ; CALL erp_bis.insert_record(999800); 执行脚本

drop function erp_bis.insert_record; 删除脚本

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值