双重循环插入

DELIMITER ;; 
CREATE PROCEDURE test_insert()

BEGIN 
DECLARE a INT DEFAULT 1; 
DECLARE b TINYINT DEFAULT 1; 
WHILE (a <= 100) DO 
-- repeat 


SET a = a + 1; 
-- select a; 
WHILE (b <=20) DO 
insert into school_sp_mj(school_id,mojor_id,status) values(a,b,1); 
SET b = b + 1; 
-- select b; 
END WHILE; 

SET b = 1; 
-- select a; 
-- until a >= i_PlayerCount 
-- end repeat; 
END WHILE; 
commit; 
END;; 
CALL test_insert();

单循环插入

DELIMITER ;; 
CREATE PROCEDURE test_insert() 
BEGIN 
DECLARE y TINYINT DEFAULT 1;
WHILE y<20
DO
insert into school_sp_mj(school_id,mojor_id,status) values(1,y,1); 
SET y=y+1; 
END WHILE ; 
commit; 
END;; 
CALL test_insert();

 

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2021-04-30
  • 2021-12-01
猜你喜欢
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-07-24
相关资源
相似解决方案