• 利用存储过程批量造数据


    一、性能测试中,我们有时候为了测试性能的准确性,会往数据库批量造一些数据,下面介绍利用存储过程来实现

    1、mysql实现

    drop procedure if exists t_add; -- 如果存在t_add 存储过程则删除
    create procedure t_add(num int)
    
    begin
    declare i int;
    set i=0;
    while i<num do
    
    insert into sudents values ('',concat('张三',i+1),'',18,'计算机','北京市海淀区');
    insert into score values('',i+1,'计算机','81');
    
    set i=i+1;
    end while;
    end;
    
    call t_add(100000); -- 调用存储过程,插入10万条数据

    2、oracle实现

    create or replace procedure t_add(num int) -- 如果存在t_add 存储过程则替换
    as
    i int;
    
    begin
    i:=0;
    while i<num LOOP
    
    insert into sudents values (sys_guid(),concat('张三',i),'',18,'计算机',to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'北京市海淀区');
    insert into score values('',i,'计算机','81');
    
    i:=i+1; 
    commit; 
    end LOOP; 
    end;
    
    call t_add(100000); -- 调用存储过程,插入10万条数据
  • 相关阅读:
    002: Opencv 4.0代码执行
    Opencv4.0+cmake3.13.3+vs2017源码编译
    ubuntu 18.0Lts +YouCompleteMe插件安装
    pip 安装keras
    pip 安装paddle
    pip 安装 tensorboardX
    pip 安装pytorch 命令
    TT信息-4-Spring Boot/Spring Cloud
    TT信息-3-Spring/Spring MVC
    TT信息-2设计模式
  • 原文地址:https://www.cnblogs.com/xiaoxitest/p/6242524.html
Copyright © 2020-2023  润新知