双重循环插入
<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