Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the for loop statement of mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

How to write the for loop statement of mysql? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

How to write the for loop statement of mysql

MySQL does not support for loop statements. MySQL supports while loop, repeat loop and loop loop.

1.while cycle

Delimiter / / # defines the identifier as a double slash drop procedure if exists test; # if there is a test stored procedure, delete create procedure test () # to create a no-parameter stored procedure named test begin declare i int; # declare the variable set I = 0 # variable assignment while I

< 10 do #结束循环的条件: 当i大于10时跳出while循环 insert into test values (i); #往test表添加数据 set i = i + 1; #循环一次,i加一 end while; #结束while循环 select * from test; #查看test表数据 end // #结束定义语句 call test(); #调用存储过程 2.repeat循环 delimiter // #定义标识符为双斜杠 drop procedure if exists test; #如果存在test存储过程则删除 create procedure test() #创建无参存储过程,名称为test begin declare i int; #申明变量 set i = 0; #变量赋值 repeat insert into test values (i); #往test表添加数据 set i = i + 1; #循环一次,i加一 until i >

10 end repeat; # conditions for ending the loop: when I is greater than 10:00, jump out of the repeat loop select * from test; # View the test table data end / / # end the definition statement call test (); # call the stored procedure

3.loop cycle

Delimiter / / # defines the identifier as a double slash drop procedure if exists test; # if there is a test stored procedure, delete create procedure test () # to create a no-parameter stored procedure named test begin declare i int; # declare the variable set I = 0 # variable assignment lp: loop # lp is the loop name, and optionally loop is the keyword insert into test values (I); # add data set I = I + 1 to the test table # cycle once, I plus one if I > 10 then # conditions for ending the cycle: when I is greater than 10:00, jump out of the loop loop leave lp; end if; end loop; select * from test # View test table data end / / # end definition statement call test (); # call stored procedure

MySQL is a relational database management system developed by the Swedish company MySQL AB and belongs to the products of Oracle. MySQL is one of the most popular relational database management systems. In the aspect of WEB application, MySQL is one of the best RDBMS (Relational Database Management System) application software. MySQL is a relational database management system in which relational databases store data in different tables instead of all data in one large warehouse, which increases speed and flexibility.

After reading the above, have you mastered how to write the for loop statement of mysql? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report