cursorThe set of rows returned by the select query is called a result set. The rows in the result set are retrieved based on the SQL statement you entered. If you do not use a cursor, you will not be able to get the first row, the first ten rows, or the next row. The following are some common cursor phenomena and characteristics
Here are the steps to use cursor
DECLARE cs CURSOR FOR SELECT * FROM customers WHERE cust_email IS NULL; I thought everything was fine, but it gave me an error There is nothing wrong with the syntax. Try adding @ in front of cs, and the error message still appears when running. Some people say that cursors can only be used in stored procedures. Is that true? Now let's try using cursors in stored procedures CREATE PROCEDURE procedure1 () BEGIN DECLARE cur1 CURSOR FOR SELECT * FROM customers WHERE cust_id IS NULL tianyoutianyou; END Still error Change again delimiter // CREATE PROCEDURE procedure1 () BEGIN DECLARE cur1 CURSOR FOR SELECT * FROM customers WHERE cust_id IS NULL; END This time we successfully declared the cursor Is it because we changed the delimiter that we successfully created the cursor? Let's try again CREATE PROCEDURE procedure1() DECLARE cur1 CURSOR FOR SELECT * FROM customers WHERE cust_id IS NULL; This is also wrong. Let's try to see if the cursor can be successfully created without using a stored procedure. delimiter // DECLARE cur2 CURSOR FOR SELECT * FROM orders ; Or maybe this delimiter // DECLARE cur2 CURSOR FOR SELECT * FROM orders // These two types also have 8 lines After trying so many times, the only successful statement is the following delimiter // CREATE PROCEDURE procedure1() BEGIN DECLARE cur1 CURSOR FOR SELECT * FROM customers WHERE cust_id IS NULL; END Next we use the cursor to retrieve data Unfortunately, MySQL does not have a data type like Oracle's %ROWTYPE. Let's try to use a cursor to retrieve a certain type of data in the customers table. triggerA trigger is a specific stored procedure that is automatically executed when a specific activity occurs in the database. Generally speaking, constraints are processed faster than triggers, so constraints should be used whenever possible. This is the end of this article about how to use cursor triggers in MySQL. For more relevant MySQL cursor trigger content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to install tomcat8 in docker
>>: Detailed explanation of the use of the clip-path property in CSS
Preface This article mainly introduces the releva...
Get daily statistics When doing a project, you ne...
When we want to add a shadow to a rectangle or ot...
Examples: Through the PHP background code, you ca...
MySQL's index types include normal index, uni...
The following error occurred while installing the...
Table of contents MySQL's current_timestamp p...
Are you still using rem flexible layout? Does it ...
When newbies develop div+css, they need to name t...
Usually a CSS selector selects from top to bottom...
1. View the current host name [root@fangjian ~]# ...
mktemp Create temporary files or directories in a...
Table of contents 0. The kernel tree that comes w...
Enable remote access rights for mysql By default,...
Vuex is a state management pattern developed spec...