What is MySQL Cursor? What are its main properties?



In Computer science and technology, a database cursor is a control structure that enables traversal over the records in a database. Cursor in MySQL is almost the same as a cursor in other databases. MySQL cursor is a kind of loop facility given to traverse in the result of SQL one by one. We can operate on every result by using the cursor in MySQL. Cursors are supported in stored procedures, functions, and triggers only. MySQL cursor is available from version 5 or greater. Followings are the three main properties of MySQL cursor −

READ ONLY

By using MySQL cursor, we cannot update any table.

Non-Scrollable

MySQL cursors always fetch the rows in one direction i.e. from top to bottom. In other words, we can say that we cannot fetch rows in reverse order and we cannot skip rows or jump to the specific row in result set.

Asensitive

MySQL cursor is asensitive in nature that is it cannot create a copy of the table. It is faster than the other type of cursor i.e. insensitive cursor.


Advertisements