This article uses examples to explain the principles and usage of MySQL cursors. Share with you for your reference, the details are as follows: In this article:
Release date: 2018-04-18 What is a cursor:
Replenish:
Create a cursor:
Using cursors:
create procedure p2() begin declare id int; declare name varchar(15); --Declare cursor declare mc cursor for select * from class; -- Open the cursor open mc; -- Get result loop -- Loop and transfer the contents of the table to class2 fetch mc into id,name; -- Here is to display the result insert into class2 values(id,name); -- Close the cursor end loop; close mc; end; The above code will have an error create procedure p3() begin declare id int; declare name varchar(15); declare flag int default 0; --Declare cursor declare mc cursor for select * from class; declare continue handler for not found set flag = 1; -- Open the cursor open mc; -- Get the result l2:loop fetch mc into id,name; if flag=1 then -- when fetch fails, handler continues leave l2; end if; -- Here is to display the result insert into class2 values(id,name); -- Close the cursor end loop; close mc; end; call p3();-- no error select * from class2; Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL transaction operation skills", "MySQL stored procedure skills", "MySQL database lock related skills summary" and "MySQL common function summary" I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
>>: Using Openlayer in Vue to realize loading animation effect
This article uses examples to illustrate the use ...
Copy code The code is as follows: <object id=&...
nohup command: If you are running a process and y...
The marquee element can achieve simple font (image...
1. Monitoring planning Before creating a monitori...
Table of contents Preface 1. Deployment and Confi...
During the development process, we often use the ...
background Ever wondered how to create a shadow e...
Table of contents The first method: router-link (...
Table of contents Using conditional types in gene...
The complete steps of Centos7 bridge network conf...
Since myeclipse2017 and idea2017 are installed on...
1. What are the formats of lines? You can see you...
This article example shares the specific code for...
This article shares the summary of the JS mineswe...