Câu hỏi phỏng vấn MySQL
Câu hỏi

What is cursor used in MySQL? Wha...

Câu trả lời

In MySQL, a cursor is a database object used to iterate through a set of rows returned by a query, allowing for row-by-row processing. This is particularly useful in stored procedures, where you might need to process each row individually[1][2][3][5].

Properties of MySQL Cursors

MySQL cursors have several key properties:

  1. Asensitive: The server may or may not make a copy of its result table. This means the cursor might not reflect changes made to the tables by other transactions after the cursor was created[2].

  2. Read-only: Cursors in MySQL are non-updatable, which means you cannot use a cursor to modify data in the underlying tables[2].

  3. Nonscrollable: MySQL cursors can only move forward through the result set and cannot skip rows or move backwards. Once a row has been fetched, it cannot be fetched again without re-opening the cursor[2][3].

  4. Lifecycle: The typical lifecycle of a cursor in MySQL involves several steps:

    • Declaration: You declare a cursor with a specific SQL query.
    • Opening: Before fetching rows, the cursor must be opened.
    • Fetching: Rows are retrieved one at a time from the cursor.
    • Closing: After all rows are processed, the cursor should be closed to free up resources[1][2][3][5].
  5. Scope: Cursors are local to the stored procedure, function, or trigger in which they are declared. They cease to exist once the stored program ends unless...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

What is Stored Function in MySQL. How are they different from Stored Procedure?

middle

What are different TEXT data types in MySQL. What is difference between TEXT and VARCHAR ?

junior

Describe BLOB in MySQL. What is it used for?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào