CLOSE Statement
This MariaDB tutorial explains how to use the CLOSE statement to close a cursor in MariaDB with syntax and examples.
Description
The final step in MariaDB is to close the cursor once you have finished using it.
Syntax
The syntax to close a cursor in MariaDB is:
CLOSE cursor_name;
Parameters or Arguments
cursor_name
The name of the cursor that you wish to close.
Example
Let's look at how to close a cursor in MariaDB using the CLOSE statement.
For example:
CLOSE c1;
This CLOSE statement example would close the cursor called c1 in MariaDB.
Below is a function that demonstrates how to use the CLOSE statement:
DELIMITER //
CREATE FUNCTION FindSize ( name_in VARCHAR(50) )
RETURNS INT READS SQL DATA
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE TotalSize INT DEFAULT 0;
DECLARE c1 CURSOR FOR
SELECT SUM(file_size)
FROM pages
WHERE site_name = name_in;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN c1;
FETCH c1 INTO TotalSize;
CLOSE c1;
RETURN TotalSize;
END; //
DELIMITER ;