【MySQL】批量数据循环插入

双重循环插入DELIMITER ;;CREATE PROCEDURE test_insert()BEGINDECLARE a INT DEFAULT 1;DECLARE b TINYINT DEFAULT 1;WHILE (a = 100) DO– repeatSET a = a + 1;– select a;WHILE (b =20) DOinsert into school_sp_mj(school_id,mojor_id,status) values(a

双重循环插入

<span style=”color: #0000ff;”>BEGIN
<span style=”color: #0000ff;”>DECLARE a <span style=”color: #0000ff;”>INT <span style=”color: #0000ff;”>DEFAULT <span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>DECLARE b <span style=”color: #0000ff;”>TINYINT <span style=”color: #0000ff;”>DEFAULT <span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>WHILE (a <span style=”color: #808080;”><= <span style=”color: #800000; font-weight: bold;”>100<span style=”color: #000000;”>) DO
<span style=”color: #008080;”>–<span style=”color: #008080;”> repeat

<span style=”color: #0000ff;”>SET a <span style=”color: #808080;”>= a <span style=”color: #808080;”>+ <span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>;
<span style=”color: #008080;”>–<span style=”color: #008080;”> select a;
<span style=”color: #0000ff;”>WHILE (b <span style=”color: #808080;”><=<span style=”color: #800000; font-weight: bold;”>20<span style=”color: #000000;”>) DO
<span style=”color: #0000ff;”>insert <span style=”color: #0000ff;”>into school_sp_mj(school_id,mojor_id,status) <span style=”color: #0000ff;”>values(a,b,<span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>);
<span style=”color: #0000ff;”>SET b <span style=”color: #808080;”>= b <span style=”color: #808080;”>+ <span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>;
<span style=”color: #008080;”>–<span style=”color: #008080;”> select b;
<span style=”color: #0000ff;”>END <span style=”color: #0000ff;”>WHILE<span style=”color: #000000;”>;

<span style=”color: #0000ff;”>SET b <span style=”color: #808080;”>= <span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>;
<span style=”color: #008080;”>–<span style=”color: #008080;”> select a; <span style=”color: #008080;”>
–<span style=”color: #008080;”> until a >= i_PlayerCount <span style=”color: #008080;”>
–<span style=”color: #008080;”> end repeat;
<span style=”color: #0000ff;”>END <span style=”color: #0000ff;”>WHILE<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>commit<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>END<span style=”color: #000000;”>;;
CALL test_insert();

单循环插入

y y school_sp_mj(school_id,status) (,y, yy

作者: dawei

【声明】:永州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部