当前位置:网站首页>What are the circular statements of MySQL
What are the circular statements of MySQL
2022-06-29 04:22:00 【Yisu cloud】
MySQL What are the loop statements of
This article “MySQL What are the loop statements of ” Most people don't quite understand the knowledge points of the article , So I made up the following summary for you , Detailed content , The steps are clear , It has certain reference value , I hope you can gain something after reading this article , Let's take a look at this article “MySQL What are the loop statements of ” Article bar .
mysql There are three common ways of cycling :while、repeat and loop loop . There is another kind. goto, It is not recommended to use .

1.while loop
-- Set up mysql The separator is //, That means , When it comes to the next one // when , Overall execution SQL sentence DELIMITER // DROP PROCEDURE if EXISTS ‘test’; # If there is test Stored procedures are deleted CREATE procedure test() # Create a parameterless stored procedure , The name is testBEGIN DECLARE i INT; # Declare variables SET i = 0; # Variable assignment WHILE i# Conditions for ending the cycle : When i Greater than 5 Jump out when while loop INSERT INTO test VALUES(i+11,'test','20'); # Go to test Table add data SET i = i+1; # Cycle time ,i Add 1END WHILE; # end while loop SELECT * FROM test; # see test Table data END // # End definition statement CALL test(); # Calling stored procedure DELIMITER ; # Reset the separator to ;
2.repeat loop
DELIMITER // DROP PROCEDURE IF EXISTS test; CREATE PROCEDURE test() BEGIN DECLARE i INT; SET i = 0; REPEAT INSERT INTO test VALUES(i+11,'test','20'); # Go to test Table add data SET i = i + 1; # Cycle time ,i Add one UNTIL i > 10 END REPEAT; # Conditions for ending the cycle : When i Greater than 10 Jump out when repeat loop SELECT * FROM test; END // CALL test(); DELIMITER ;
3.loop loop
DELIMITER // DROP PROCEDURE IF EXISTS test; CREATE PROCEDURE test() BEGIN DECLARE i INT; SET i = 0; lp : LOOP # lp Is the body name of the loop , Feel free to loop Keyword INSERT INTO test VALUES(i+11,'test','20'); # Go to test Table add data SET i = i + 1; # Cycle time ,i Add one IF i > 10 THEN # Conditions for ending the cycle : When i Greater than 10 Jump out when loop loop LEAVE lp; END IF; END LOOP; SELECT * FROM test; END // CALL test(); DELIMITER ;
That's about “MySQL What are the loop statements of ” The content of this article , I believe we all have a certain understanding , I hope the content shared by Xiaobian will be helpful to you , If you want to know more about it , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- MySQL subquery
- Remediation for Unsafe Cryptographic Encryption
- How to create robots Txt file?
- Libuv库概述及libevent、libev、libuv对比(转载)
- The second meeting of the Second Council of Euler open source community was held, and Xinhua III, hyperfusion and Godson Zhongke became members of the Council
- LabVIEW displays Unicode characters
- 请问大佬,Oracle CDC报错 Call snapshotState on closed sou
- Ansible最佳实践之Playbook不同上下文提权Demo
- 043. (2.12) what will happen if you become enlightened?
- 1019 digital black hole
猜你喜欢

MySQL subquery

快速开发项目-VScode插件

【HackTheBox】dancing(SMB)

PostgreSQL has a cross database references are not implemented bug
![[C language] address of stack memory associated with local variable 'num' returned](/img/34/f8cf86a18ed461b25073b740dece45.png)
[C language] address of stack memory associated with local variable 'num' returned

Libuv库概述及libevent、libev、libuv对比(转载)

Blue Bridge Cup DFS (I)

女程序员晒出5月的工资条:工资是高,但是真累,网友评论炸锅了

C language -- branch structure

SEAttention 通道注意力机制
随机推荐
Ansible最佳实践之Playbook不同上下文提权Demo
Redis cache penetration, cache breakdown, cache avalanche
How to create a subtype like relationship between two generic classes when the classes are generic related
lua-protobuff emmy-lua 轮子
Remote connection of raspberry pie in VNC Viewer Mode
Open source demo| you draw and I guess -- make your life more interesting
1016 part a+b
Talking about Canary deployment
1015 德才论
访问数据库时出现错误
How to merge upstream and downstream SQL data records
JVM_ 16_ Garbage collector
1018 锤子剪刀布
请问大佬,Oracle CDC报错 Call snapshotState on closed sou
Path and LD_ LIBRARY_ Example of path usage
How to keep database and cache consistent
C language -- branch structure
LabVIEW显示Unicode字符
1019 digital black hole
ROS TF coordinate transformation Library & rewrite to create high frequency coordinate transformation broadcaster