Javatpoint Logo
Javatpoint Logo

MySQL Cursor

In MySQL, Cursor can also be created. Following are the steps for creating a cursor.

1. Declare Cursor

A cursor is a select statement, defined in the declaration section in MySQL.

Syntax

Parameter:

cursor_name: name of the cursor

select_statement: select query associated with the cursor

2. Open Cursor

After declaring the cursor the next step is to open the cursor using open statement.

Syntax

Parameter:

cursor_name: name of the cursor which is already declared.

3. Fetch Cursor

After declaring and opening the cursor, the next step is to fetch the cursor. It is used to fetch the row or the column.

Syntax

Parameter:

cursor_name: name of the cursor

variable_list: variables, comma separated, etc. is stored in a cursor for the result set

4. Close Cursor

The final step is to close the cursor.

Syntax

Parameter:

Cursor_name: name of the cursor

Example for the cursor:

Step 1: Open the database and table.

MySQL Cursor

Step 2: Now create the cursor.

Query:

MySQL Cursor

Step 3: Now call the cursor.

Query:

MySQL Cursor
Next TopicMySQL Functions




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA