Home  >  Article  >  Database  >  MySql code example for inserting data in a loop

MySql code example for inserting data in a loop

不言
不言forward
2019-03-22 10:57:313212browse

The content of this article is about the code example of MySql loop insertion of data. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

MySql uses stored procedures to insert data

#创建存储过程
CREATE PROCEDURE test_insert () 
    #开始
    BEGIN
        #定义变量 
        DECLARE i INT DEFAULT 1;
            #条件判断
            WHILE i<1000000 
            #执行
            DO 
                #SQL
                INSERT SQL ;
                #变量增加
                SET i=i+1;
            #结束循环 
            END WHILE ;
        #提交 
        commit; 
    #结束
    END;
#执行
CALL test_insert();    
#删除存储过程
drop procedure test_insert ;
#查看存储过程
SHOW PROCEDURE STATUS ;
#查看创建存储过程的语句
SHOW CREATE PROCEDURE test_insert8 ;

This article has ended here. For more other exciting content, you can pay attention to the MySQL tutorial video on the PHP Chinese website Column!

The above is the detailed content of MySql code example for inserting data in a loop. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete