当前位置:网站首页>Example analysis of while, repeat and loop loops in MySQL process control
Example analysis of while, repeat and loop loops in MySQL process control
2022-07-29 03:14:00 【Yisu cloud】
MySQL Process control while、repeat、loop Cycle example analysis
Today I'd like to share with you MySQL Process control while、repeat、loop Relevant knowledge points of circular example analysis , Detailed content , Clear logic , I believe most people still know too much about this knowledge , So share this article for your reference , I hope you will gain something after reading this article , Now let's take a look .

Preface
A loop is a segment that appears only once in a program , However, code may run multiple times in a row .
The code in the loop runs a certain number of times , Or run to the end of the loop when certain conditions are established .

Cycle classification :
while
repeat
loop
Cycle control :
leave Be similar to break, Jump out of , End the current cycle
iterate Be similar to continue, continue , End this cycle , Go on for the next time
while loop
【 label :】while The loop condition do The loop body ;end while【 label 】;
-- Create test table create table user (uid int primary_key,username varchar ( 50 ),password varchar ( 50 ));
-- ------- stored procedure -whiledelimiter $$create procedure proc16_while1(in insertcount int)begindeclare i int default 1;label:while i<=insertcount doinsert into user(uid,username,`password`) values(i,concat('user-',i),'123456');set i=i+1;end while label;end $$delimiter ;call proc16_while(10);Stored procedure syntax is fixed :delimiter $$ create peocedure Circular name ( Parameters )begin Code end $$ delimiter;
Note that when writing the loop body , You must know the variables of the loop , use declare i int default The default value is
Then is dlabel:while Judge the condition do The loop body end while label; end && There must be
-- ------- stored procedure -while + leavetruncate table user;delimiter $$create procedure proc16_while2(in insertcount int)begindeclare i int default 1;label:while i<=insertcount doinsert into user(uid,username,`password`) values(i,concat('user-',i),'123456');if i=5 then leave label;end if;set i=i+1;end while label;end $$delimiter ;call proc16_while2(10);If you need to jump out of the loop internally , use if Judge , But at the end of the day end if ending
there leave Namely Out of the loop , be relative to break
-- ------- stored procedure -while+iteratetruncate table user;delimiter $$create procedure proc16_while3(in insertcount int)begindeclare i int default 1;label:while i<=insertcount doset i=i+1;if i=5 then iterate label;end if;insert into user(uid,username,`password`) values(i,concat('user-',i),'123456');end while label;end $$delimiter ;call proc16_while3(10);there iterate be relative to continue Do not execute the following code when encountering
repeat loop
repeat The loop body ;until Conditional expression end repeat [ label ];
-- ------- stored procedure - Cycle control -repeatuse mysql7_procedure;truncate table user;delimiter $$create procedure proc18_repeat(in insertCount int)begindeclare i int default 1;label:repeatinsert into user(uid, username, password) values(i,concat('user-',i),'123456');set i = i + 1;until i > insertCountend repeat label;select ' The loop ends ';end $$delimiter ;call proc18_repeat(100);This is relative to , In any case, the loop will be executed once , Then make internal judgment , If you are satisfied, just jump out
loop loop
loop The loop body ;if Conditional expression thenleave [ label ];end if;end loop;
-- ------- stored procedure - Cycle control -looptruncate table user;delimiter $$create procedure proc19_loop(in insertCount int)begindeclare i int default 1;label:loopinsert into user(uid, username, password) values(i,concat('user-',i),'123456');set i = i + 1;if i > 5thenleave label;end if;end loop label;select ' The loop ends ';end $$delimiter ;call proc19_loop(10);This and repeat The difference is , After execution , utilize leave Out of the loop , No matter which one is used, it can achieve the effect we need , But the application scenario in business ,while Still relatively more .
That's all “MySQL Process control while、repeat、loop Cycle example analysis ” All the content of this article , Thank you for reading ! I believe you will gain a lot after reading this article , Xiaobian will update different knowledge for you every day , If you want to learn more , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- 扫雷简单版
- C traps and defects Chapter 3 semantic "traps" 3.1 pointers and arrays
- Digital image processing Chapter 10 - image segmentation
- Redis之sentinel哨兵集群怎么部署
- 4000 多字学懂弄通 js 中 this 指向问题,顺便手写实现 call、apply 和 bind
- MYSQL入门与进阶(十二)
- HTB-Blue
- 3D高级渲染器:Artlantis studio 2021.2中文版
- Why did I choose the test when the development salary was high?
- Introduction and advanced level of MySQL (11)
猜你喜欢

Redis configuration cache expiration listening event trigger

ShardingSphere之水平分表实战(三)

【FreeSwitch开发实践】media bug获取通话语音流

【机器人学习】机械臂抓手matlab运动学与admas动力学分析

MySql的安装配置超详细教程与简单的建库建表方法

13_ UE4 advanced_ Montage animation realizes attack while walking

sqlilabs less-32~less-33

01-SDRAM:初始化模块的代码

Chapter 09_ Use of performance analysis tools

基于单片机烟雾温湿度甲醛监测设计
随机推荐
Flask的创建的流程day05-06之创建项目
13_ UE4 advanced_ Montage animation realizes attack while walking
VIM common commands
MySQL large table joint query optimization, large transaction optimization, avoiding transaction timeout, lock wait timeout and lock table
MYSQL入门与进阶(十四)
Li Shuo, vice president of Baidu: it's a good thing that China's labor costs rise with the support of digital technology
4000 多字学懂弄通 js 中 this 指向问题,顺便手写实现 call、apply 和 bind
VASP calculation task error: M_ divide:can not subdivide 8 nodes by 6
My approval function of conference OA project
Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.
力扣刷题之分数加减运算(每日一题7/27)
【FreeSwitch开发实践】media bug获取通话语音流
Chapter 09_ Use of performance analysis tools
增量实时灾备笔记
2022-07-28 第四小组 修身课 学习笔记(every day)
[QNX hypervisor 2.2 user manual]9.11 RAM (under update)
CentOS install mysql8
12_ue4进阶_换一个更好看的人物模型
3D高级渲染器:Artlantis studio 2021.2中文版
Hangao database best practice configuration tool Hg_ BP log collection content