title: How to loop over XML elements in a MySQL stored procedure?
body: <p>The MySQL documentation has this example:</p>
  
  <pre><code>mysql&gt; DELIMITER |
  
  mysql&gt; CREATE PROCEDURE myproc ()
      -&gt; BEGIN
      -&gt;   DECLARE i INT DEFAULT 1;
      -&gt;   DECLARE xml VARCHAR(25) DEFAULT '&lt;a&gt;X&lt;/a&gt;&lt;a&gt;Y&lt;/a&gt;&lt;a&gt;Z&lt;/a&gt;';
      -&gt;
      -&gt;   WHILE i &lt; 4 DO
      -&gt;     SELECT xml, i, ExtractValue(xml, '//a[$i]');
      -&gt;     SET i = i+1;
      -&gt;   END WHILE;
      -&gt; END |
  </code></pre>
  
  <p>Is there a way to accomplish this without hard-coding the number of elements (the value <code>4</code> in this example)?</p>
  
  <p><strong>UPDATE</strong>
  I'm looking for a general solution. Don't be distracted by the specific XML shown in the question, it's just an example straight out of the MySQL manual page.</p>