In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to insert data cyclically in the table in Mysql, the contents of the article are carefully selected and edited by the author, with a certain pertinence, and is of great significance to everyone's reference, let's work with the author to understand how to insert data cyclically in the table in Mysql.
See what storage engine your mysql now offers:
Mysql > show engines
Take a look at your mysql's current default storage engine:
Mysql > show variables like'% storage_engine%'
Create a tabl
Create table per2 (id int,name varchar (20))
So we manually set delimiter to / /
Delimiter / /
Create procedure per3 ()
Begin
Declare num int
Set num=1
While num
< 20000000 do insert into per2(id,name) values(num,concat("fan", num)); set num=num+1; end while; end // 其中concat("fan", num),相当于oracle中fan||i的拼接效果,但是mysql不支持这样拼接 之后我们要调用这个procedure,才会插入数据 其中concat("fan", num),相当于oracle中fan||i的拼接效果,但是mysql不支持这样拼接 之后我们要调用这个procedure,才会插入数据 (mysql@localhost) [fandb]>Call per3 (); / /
Since I didn't change the delimiter' back, I typed'; 'and didn't execute it, so I still need / /
Other methods of use
While end while:
Mysql > DELIMITER / /
Mysql > CREATE PROCEDURE proc4 ()
-> begin
-> declare var int
-> set var=0
-> while var insert into t values (var)
-> set var=var+1
-> end while
-> end
-> / /
Repeat end repeat:
It checks the results after the operation is performed, while while performs a pre-check.
Mysql > DELIMITER / /
Mysql > CREATE PROCEDURE proc5 ()
-> begin
-> declare v int
-> set vault 0
-> repeat
-> insert into t values (v)
-> set v=v+1
-> until v > = 5
-> end repeat
-> end
-> / /
Repeat- cycle body until cycle condition endrepeat
Loop endloop:
The loop loop does not require initial conditions, which is similar to the while cycle and does not require a closing bar like the repeat loop.
The meaning of leave surprise sentence is to leave the cycle.
Mysql > DELIMITER / /
Mysql > CREATE PROCEDURE proc6 ()
Begin
Declare v int
Set vault 0
LOOP_LABLE:loop
Insert into t values (v)
Set v=v+1
If v > = 5 then
Leave LOOP_LABLE
End if
End loop
End
/ /
After reading the above about how to insert data into the table in Mysql, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.