title: MySQL cursor fetch NULL
body: <p>Why both my variables output <code>NULL</code>? <code>SELECT</code> part of the cursor is working properly.</p>
  
  <pre><code>CREATE PROCEDURE p2()
    BEGIN
      # Account table
      DECLARE accountid INT;
      DECLARE accountname VARCHAR(1000);
  
      # 1. cursor finished/done variable comes first
      DECLARE done INT DEFAULT 0;
      # 2. the curser declaration and select
      DECLARE c_account_id_name CURSOR FOR SELECT
                                             accountid,
                                             accountname
                                           FROM temp.test;
      # 3. the continue handler is defined last
      DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
  
      OPEN c_account_id_name;
      SET accountid = 0;
      SET accountname = '';
  
      read_loop: LOOP
        FETCH c_account_id_name
        INTO accountid, accountname;
        IF done
        THEN
          LEAVE read_loop;
        END IF;
        SELECT accountname;
      END LOOP;
    END;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dvbrx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dvbrx.png" alt="enter image description here"></a></p>