title: How to simulate a print in a MySQL Stored Procedure
body: <p>I have a MySQL stored procedure with a few cursors.  I want to print a value to send output back to the client. <a href="http://www.webyog.com/en/" rel="noreferrer">SQLyog Enterprise</a>.</p>
  
  <p>I tried declaring a variable as TEXT and concatenating inside the loop but that does not work, at least not the way I was trying to do it.</p>
  
  <pre><code>DECLARE _output TEXT;
  DECLARE _ID INT DEFAULT 0;
  DECLARE cur1 CURSOR FOR SELECT ID FROM CodeID;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  
  OPEN cur1;
  
  REPEAT
    FETCH cur1 INTO _ID;
    IF NOT done THEN
      SET _output = _ID; /*SEE ALT BELOW*/
  
    END IF;
  UNTIL done END REPEAT;
  CLOSE cur1;
  
  SELECT _output;
  </code></pre>
  
  <p>I've tried:</p>
  
  <pre><code>SET _output = _output + _ID
  </code></pre>
  
  <p>and </p>
  
  <pre><code>SET _output = CONCAT(_output,_ID)
  </code></pre>
  
  <p>but they both just return NULL</p>
  
  <p><code>SET _output = _ID;</code> just gives me the last fetched row.  Which is helpful but not entirely what I wanted.</p>
  
  <p>What's the best way to have each fetched row output to screen to reproduce the MySQL print in a MySQL Stored Procedure?</p>