Introduction to query commands for MySQL stored procedures

Introduction to query commands for MySQL stored procedures

As shown below:

select name from mysql.proc where db='database name';

or

select routine_name from information_schema.routines where routine_schema='database name';

or

show procedure status where db='database name';
SHOW CREATE PROCEDURE database.Stored procedure name;

Supplement: MySQL stored procedure - loop through the query result set

1. Create a stored procedure

When creating a stored procedure according to MySQL syntax, it is important to note that if you loop through the result set of the query, you need to take out the data in the result set for operation.

CREATE DEFINER=`root`@`%` PROCEDURE `alter_view_counts`()
BEGIN
 #Declare end flag DECLARE end_flag int DEFAULT 0; 
 DECLARE albumId bigint; 
 #Declare cursor album_curosr
 DECLARE album_curosr CURSOR FOR SELECT album_id FROM album; 
 #Set the termination flag DECLARE CONTINUE HANDLER FOR NOT FOUND SET end_flag=1; 
 #Open the cursor OPEN album_curosr; 
 #Traverse the cursor REPEAT
 #Get the current cursor pointer record and assign the value to the custom variable FETCH album_curosr INTO albumId;
  #Use the obtained value to perform database operations UPDATE album SET album.views_count= (SELECT SUM(light_chat.views_count) FROM `light_chat` WHERE light_chat.album_id = albumId) WHERE album.album_id = albumId;
 # Determine whether to end UNTIL end_flag END REPEAT according to end_flag; 
 #Close the cursorclose album_curosr; 
END

2. Calling a stored procedure

CALL alter_view_counts()

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Solution to the problem that MySQL commands cannot be entered in Chinese
  • Detailed explanation of encoding issues during MySQL command line operations
  • Introduction to the use of MySQL source command
  • MySQL commonly used SQL and commands from entry to deleting database and running away
  • Implementation of mysql using mysqlbinlog command to restore accidentally deleted data
  • Three methods of automatically completing commands in MySQL database
  • MySQL password contains special characters & operation of logging in from command line
  • Mysql desktop tool SQLyog resources and activation methods say goodbye to the black and white command line
  • MySQL login and exit command format
  • How to use the MySQL authorization command grant
  • Summary of MySQL basic common commands

<<:  Introduction to CSS foreground and background automatic color matching technology (demo)

>>:  About the VMware vcenter unauthorized arbitrary file upload vulnerability (CVE-2021-21972)

Recommend

How to build a K8S cluster and install docker under Hyper-V

If you have installed the Win10 system and want t...

Summarize several common ranking problems in MySQL

Preface: In some application scenarios, we often ...

Detailed explanation of monitoring Jenkins process based on zabbix

1. Monitoring architecture diagram 2. Implementat...

A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

Preface Since vue3.0 was officially launched, man...

Detailed tutorial on installing MYSQL under WINDOWS

1. Download the installation package -Choose the ...

HTML tutorial, easy to learn HTML language

1. <body background=image file name bgcolor=co...

Use docker to deploy tomcat and connect to skywalking

Table of contents 1. Overview 2. Use docker to de...

Issues with Rancher deployment and importing K8S clusters

Rancher deployment can have three architectures: ...

Detailed explanation of the basic use of centos7 firewall in linux

1. Basic use of firewalld start up: systemctl sta...

Detailed examples of float usage in HTML/CSS

1. Basic usage examples of float 1. Let's fir...

Summary of the advantages of Vue3 vs. Vue2

Table of contents 1. Why do we need vue3? 2. Adva...

MySQL 5.7.20 compressed version download and installation simple tutorial

1. Download address: http://dev.mysql.com/downloa...