Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the mysql cursor

Shulou Source: shulou.com Published: 2022-05-31 10:42:40 11月15日 Update

This article mainly introduces "how to use the mysql cursor". In the daily operation, I believe many people have doubts about how to use the mysql cursor. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the mysql cursor". Next, please follow the editor to study!

Description

1. Before using the cursor, you must declare (define).

2. After the declaration, the cursor must be opened before it can be used.

3. After opening, use the cursor as needed.

4. After the cursor is used, it must be closed.

Example

Delimiter /-declarative delimiter create procedure proce_cursor ()-- declarative storage structure begindeclare tmp_barcode varchar (50);-- this quantity is used to store the book code declare tmp_bookname varchar (50);-- this quantity is used to store the book title declare stop int default 0;-- this quantity is used to store the variable value declare tmp_price float default 0 of the loop stop;-- this quantity is used to store the book price declare bookcount int default 0. -- the number of books used to store the number of # statement cursor declare cursor_book cursor for selectbarcode,bookname,pricefrom tb_bookinfo where typeid = 4 position CONTINUE HANDLER FOR SQLSTATE '02000' SET stop = 0;-- set the stop amount to 0open cursor_book;-- Open the cursor select count (*) into bookcount from tb_bookinfo where typeid = 4 -- find several books WHILE (stop < bookcount) DO-- cycle fetch cursor_book into tmp_barcode,tmp_bookname,tmp_price; if the stop amount is less than the total number of books-- cycle to get the value stored in the cursor select tmp_barcode,tmp_bookname,tmp_price;-- show the stored value set stop = stop + 1;-- finally add an end while;close cursor_book to the stop amount. End// at this point, the study on "how to use the mysql cursor" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Cursors books cursors learning loops more help practical next price delimiter instance total quantity article method theory knowledge article structure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Xiaomi MariaDB macOS