How to write the cursor in mysql
The method of cursor writing in mysql: first declare the cursor; then open the cursor, the code is [OPEN cursor_name]; then capture the cursor; finally close the cursor, the code is [CLOSE cursor_name]. More related free learning recommendation: mysql tutorial (video) mysql cursor Writing method: 1, what is a cursor In a stored procedure or function, you can use the cursor to cycle through the result set . The following is my personal opinion, the cursor is similar to the auto-increment variable i in the java loop. 2, the use of the cursor The use of the cursor includes the following three steps: 1, declare the cursor Format: DECLARE cursor_name CURSOR FOR select_statement; cursor_name: Cursor name, set by the user, it is best to know the name. select_statement: The complete query statement, the column name in the query table (detailed explanation of the following cases). 2. Turn on the cursor cursor_name: the cursor name at the time of declaration. Format: OPEN cursor_name; 3, capture cursor Format: FETCH cursor_name INTO var_name…; (…indicates that there can be more than one) cursor_name: the cursor name at the time of declaration. var_name: Custom variable name. (Detailed explanation of the following cases) 4. Close the…