title: Loop n times without using a stored procedure
body: <p>How can I write a loop that runs n times in MySql without using a stored procedure.  </p>
  
  <p>This is how I do it with a stored procedure:  </p>
  
  <pre><code>DELIMITER $$
  DROP PROCEDURE IF EXISTS test$$
  CREATE PROCEDURE test()
  BEGIN
     DECLARE count INT DEFAULT 0;
     WHILE count &lt; 10 DO
        /**Sql statement**/
        SET count = count + 1;
     END WHILE;
  END$$
  DELIMITER ;  
  </code></pre>
  
  <p>And then I execute my procedure this way:  </p>
  
  <pre><code>call test();  
  </code></pre>
  
  <p>If I remove the stored procedure and run the normal query, then it fails with this error:  </p>
  
  <blockquote>
    <p>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE count INT DEFAULT 0; WHILE count &lt; 10 DO at line' 2   </p>
  </blockquote>
  
  <p>I have looked through the Internet for a solution with no luck.  </p>
  
  <p><strong>Edit Based On comments:</strong>  </p>
  
  <p>The above stored procedure does exactly what I want: It loops 10 times and execute my sql statement. Now I want to accomplish the same thing without using a stored procedure. Something like:  </p>
  
  <pre><code>DECLARE count INT DEFAULT 0;
     WHILE count &lt; 10 DO
        /**Sql statement**/
        SET count = count + 1;
     END WHILE;  
  </code></pre>