Home  >  Article  >  Database  >  Detailed explanation of MySQL's method of creating a stored procedure and adding records in a loop

Detailed explanation of MySQL's method of creating a stored procedure and adding records in a loop

小云云
小云云Original
2018-01-17 10:31:471731browse

This article mainly introduces the method of creating stored procedures and adding records in a loop in MySQL, involving basic mysql stored procedure creation and calling related operation skills. Friends who need it can refer to it. I hope it can be a moderator for everyone.

Create first, then call:


-- 创建存储过程
DELIMITER;//
create procedure myproc()
begin
declare num int;
set num=1;
while num <= 24 do
insert into t_calendar_hour(hourlist) values(num);
set num=num+1;
end while;
commit;
end;//
-- 调用存储过程
CALL myproc();

Related recommendations:

Explain in detail the stored procedure of mysql, Cursors, transactions

A brief introduction to MySQL stored procedures and transactions

MySQL stored procedures Sample code for cursor error handling

The above is the detailed content of Detailed explanation of MySQL's method of creating a stored procedure and adding records in a loop. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn