How to create a stored procedure in MySQL and add records in a loop

How to create a stored procedure in MySQL and add records in a loop

This article uses an example to describe how to create a stored procedure in MySQL and add records in a loop. Share with you for your reference, the details are as follows:

First create, then call:

-- Create stored procedure 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 the stored procedure CALL myproc();

PS: Here are two commonly used SQL online tools for your reference (including SQL statement usage instructions):

SQL online compression/formatting tool:
http://tools.jb51.net/code/sql_format_compress

SQL code online formatting and beautification tool:
http://tools.jb51.net/code/sqlcodeformat

Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL stored procedure skills", "MySQL common function summary", "MySQL log operation skills", "MySQL transaction operation skills summary" and "MySQL database lock related skills summary"

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • Simple writing of MYSQL stored procedures and functions
  • Detailed example of MySQL data storage process parameters
  • Two ways to write stored procedures in Mysql with and without return values
  • Detailed explanation of MySQL stored procedures, cursors, and transaction examples
  • Detailed explanation of the entry-level use of MySql stored procedure parameters
  • mysql uses stored procedures to implement tree node acquisition method

<<:  Example of how to reference environment variables in Docker Compose

>>:  Fabric.js implements DIY postcard function

Recommend

Docker case analysis: Building a Redis service

Table of contents 1 Create mount directories and ...

MySQL uses UNIQUE to implement non-duplicate data insertion

SQL UNIQUE constraint The UNIQUE constraint uniqu...

IDEA uses the Docker plug-in (novice tutorial)

Table of contents illustrate 1. Enable Docker rem...

Detailed explanation of the usage of two types of temporary tables in MySQL

External temporary tables A temporary table creat...

Avoid abusing this to read data in data in Vue

Table of contents Preface 1. The process of using...

Implementation of k8s node rejoining the master cluster

1. Delete node Execute kubectl delete node node01...

Summary of MySQL log related knowledge

Table of contents SQL execution order bin log Wha...

Introduction to Linux compression and decompression commands

Table of contents Common compression formats: gz ...

About the overlap of margin value and vertical margin in CSS

Margin of parallel boxes (overlap of double margi...

Basic learning tutorial of table tag in HTML

Table label composition The table in HTML is comp...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

Web project development VUE mixing and inheritance principle

Table of contents Mixin Mixin Note (duplicate nam...