title: WHILE is not valid input at this position when running SQL in MySQL workbench
body: <p>I have created a table as follows:</p>
  
  <pre><code>create table data_table(skey int, svalue int);
  </code></pre>
  
  <p>I want to find gaps in <code>skey</code>. Say I have entries 1,2,6,7. Then running SQL should return 4 and 5. I referred <a href="https://stackoverflow.com/a/1057414/1317018">this</a> and tried executing following:</p>
  
  <pre><code>select @min_val := min(svalue), @max_val := max(svalue) from data_table;
  
  create table tmp (Field_No int);
  
  WHILE @min &lt;= @max DO
     if not exists (select * from data_table where skey = @min)
        insert into tmp (Field_No) values (@min)
     set @min = @min + 1
  END WHILE;
  
  select * from tmp
  drop table tmp
  </code></pre>
  
  <p>MySQL workbench says <code>WHILE is not valid input at this position</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/6DjCS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6DjCS.png" alt="enter image description here"></a></p>
  
  <p>PS: Am using MySQL 5.6.25</p>
  
  <p><strong>Update</strong></p>
  
  <p>Adding the whole code in stored procedure still gives me errors:</p>
  
  <p><a href="https://i.stack.imgur.com/2eo3c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2eo3c.png" alt="enter image description here"></a></p>