USE test;
DELIMITER $$
DROP PROCEDURE IF EXISTS example3$$
CREATE PROCEDURE example3( )
BEGIN

DECLARE dname VARCHAR(255);
DECLARE hasnext INT DEFAULT TRUE;

DECLARE c CURSOR FOR
SELECT displayname
FROM moma.artists
WHERE nationality = 'American'
LIMIT 20;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET hasnext = FALSE;

OPEN c;
FETCH c INTO dname;
WHILE hasnext DO
  SELECT dname;
  FETCH c INTO dname;
END WHILE;

END $$
DELIMITER ;
call example3();