Database Reference
In-Depth Information
Analysis
When the OPEN statement is processed, the query is executed, and the retrieved
data is stored for subsequent browsing and scrolling.
After cursor processing is complete, the cursor should be closed using the
CLOSE statement, as follows:
Input
CLOSE ordernumbers;
Analysis
CLOSE frees up any internal memory and resources used by the cursor, and so
every cursor should be closed when it is no longer needed.
After a cursor is closed, it cannot be reused without being opened again.
However, a cursor does not need to be declared again to be used; an OPEN
statement is sufficient.
Note
Implicit Closing If you do not explicitly close a cursor, MariaDB closes it automatically
when the END statement is reached.
Here is an updated version of the previous example:
Input
CREATE PROCEDURE processorders()
BEGIN
-- Declare the cursor
DECLARE ordernumbers CURSOR
FOR
SELECT order_num FROM orders;
-- Open the cursor
OPEN ordernumbers;
-- Close the cursor
CLOSE ordernumbers;
END;
Analysis
This stored procedure declares, opens, and closes a cursor. However, nothing is
done with the retrieved data.
 
Search WWH ::




Custom Search