zoukankan      html  css  js  c++  java
  • mysql 使用存储过程批量插数据

    #创建测试表
    DROP TABLE IF EXISTS test.test;
    CREATE TABLE test.test(
    id int(10) not null auto_increment,
    a int(10) not null,
    b int(10) not null,
    c int(10) not null,
    PRIMARY key (`id`)
    )ENGINE INNODB DEFAULT CHARSET utf8 COMMENT '测试表';
    
    #清空数据
    TRUNCATE table test.test;
    
    #定义存储过程
    delimiter //
    DROP PROCEDURE IF EXISTS insert_test_val;
    ##num_limit 要插入数据的数量,rand_limit 最大随机的数值
    CREATE PROCEDURE insert_test_val(in num_limit int,in rand_limit int)
    BEGIN
    
    DECLARE i int default 1;
    DECLARE a int default 1;
    DECLARE b int default 1;
    DECLARE c int default 1;
    
    WHILE i<=num_limit do
    
    set a = FLOOR(rand()*rand_limit);
    set b = FLOOR(rand()*rand_limit);
    set c = FLOOR(rand()*rand_limit);
    INSERT into test.test values (null,a,b,c);
    set i = i + 1;
    
    END WHILE;
    
    END
    //
    
    #调用存储过程
    call insert_test_val(100000,10);
    

    结果:

    相关链接 http://blog.sina.com.cn/s/blog_9d0b00a4010122wf.html

    MySQL 存储过程参数用法 in, out, inout: 

    http://www.blogjava.net/nonels/archive/2009/04/22/233324.html

  • 相关阅读:
    php-beanstalkd消息队列类分享
    php curl抓取类分享
    df -i 100%时处理方法
    php生成红包
    PHP牛牛游戏算法
    Yii 框架不同逻辑处理方法统一事务处理
    Linux上web服务器搭建
    Linux 上pcntl安装步骤
    PHP错误级别设置
    day40 ,epoll,数据库相关概念
  • 原文地址:https://www.cnblogs.com/lixiuran/p/6144000.html
Copyright © 2011-2022 走看看