Joke Collection Website - News headlines - mysql cursor

mysql cursor

Cursor: A data structure that can locate each record in the result set and operate on the data in the pointed record.

Create a cursor: CREATE FUNCTION function name (parameters) RETURNS data type program body

Four steps for using a cursor in a stored procedure: define the cursor, open the cursor, read the cursor data and Close the cursor.

Define cursor: DECLARE cursor name CURSOR FOR query statement

Open cursor: OPEN cursor name;

Read cursor data: FETCH cursor name INTO variable list;

Close the cursor: CLOSE cursor name;

Conditional processing statement: DECLARE processing method [CONTINUE or EXIT] HANDLER FOR problem operation;

Process control statement: jump Transfer statements (ITERATE statement and LEAVE statement), loop statements (LOOP, WHILE, REPEAT), conditional judgment statements (IF statement and CASE statement)

Create a cursor: CREATE FUNCTION function name (parameters) RETURNS data type Program body

Stored functions are very similar to stored procedures, but there are several differences:

1. Stored functions must return a value or data table, while stored procedures do not need to return.

2. Stored procedures can be called through the CALL statement, but stored functions cannot

3. Stored functions can be used in query statements, but stored procedures cannot

4. The functions of stored procedures are more powerful, including the ability to perform operations on tables (such as creating tables, deleting tables, etc.) and transaction operations

The cursor operation steps include 4 steps: define cursor, open cursor, read Get cursor data and close the cursor.

1. Create a stored procedure