title: Creating temporary table inside stored procedure
body: <p>I am working on writing my first stored procedure for MySQL. </p>
  
  <p>The stored procedure needs to create a temporary table and then insert some data into it. </p>
  
  <p>If I manually create a normal table, outside of the stored proc, so the stored proc isn't creating the temporary table the stored proc is created and does exactly what I'm after. </p>
  
  <p>If I then add the create temporary table to the stored proc instead, MySQL workbench then shows unexpected end and the en of the create statement. </p>
  
  <p>Below is my stored proc</p>
  
  <pre><code>    DELIMITER //
      CREATE PROCEDURE getLast24Hours()
      BEGIN
  #End of the below line I get unexpected end without this it works fine
          CREATE TABLE hours (`Hour` VARCHAR(8) NOT NULL, `Value` INT NOT NULL DEFAULT 0, PRIMARY KEY(`Hour`)); 
  
          DECLARE crt_time VARCHAR(8);
          DECLARE counter INT;
          DECLARE currentTime DATETIME;
  
          SET currentTime = NOW();
  
          SET crt_time = DATE_FORMAT(currentTime, '%d-%m %H');
          SET counter = 0;
          WHILE counter &lt; 23 DO
              INSERT INTO hours (`Hour`) VALUES (crt_time);
              SET currentTime = currentTime - INTERVAL 1 HOUR;
              SET crt_time = DATE_FORMAT(currenttime, '%d-%m %H');
              SET counter = counter + 1;
          END WHILE;
      END //
      DELIMITER ; 
  </code></pre>
  
  <p>I can't see anything to say that creating a temporary table isn't possible so what am I doing wrong. </p>