OPEN Statement
This MariaDB tutorial explains how to use the OPEN statement to open a cursor in MariaDB with syntax and examples.
Description
Once you've declared your cursor in MariaDB, the next step is to use the OPEN statement to open the cursor.
Syntax
The syntax to open a cursor using the OPEN statement in MariaDB is:
OPEN cursor_name;
Parameters or Arguments
cursor_name
The name of the cursor that you wish to open.
Example
Let's look at how to open a cursor using the OPEN statement in MariaDB.
For example:
OPEN c1;
This OPEN statement example would open a cursor in MariaDB called c1.
Below is a function that demonstrates how to open a cursor.
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 ;