title: WHILE loop in DBeaver giving syntax error
body: <p>I am trying to create a procedure in DBeaver that simply fetches some values as parameters from a datatable (here named 'tempTable') and uses them in a loop to fetch data from another datatable (here 'oldTable), run some calculations and push the new data to the final datatable (here 'newTable).</p>
  <p>The tempTable has multiple rows so I was thinking of setting up a loop. However, for some reason every attempt has failed (I have tried various syntax for WHILE and even tried with FOR but without success). Here is my code:</p>
  <pre><code>CREATE DEFINER=`xxx`@`localhost` PROCEDURE `xxx`.`xxx`
  BEGIN
      SET @counter = 1;
      WHILE (@counter &lt;= 10)
          LOOP
          SET @tld_temp = (SELECT tld_iter FROM tempTable t WHERE t.ident = @counter);
          SET @country_temp = (SELECT country_iter FROM tempTable t WHERE t.ident = @counter);
          SET @device_temp = (SELECT device_iter FROM tempTable t WHERE t.ident = @counter);
          SET @ttype_temp = (SELECT ttype_iter FROM tempTable t WHERE t.ident = @counter);
          SET @url = CONCAT('%www.xxxxx.', @tld_temp, '/', @ttype_temp, '%');
          
          INSERT INTO newTable(yr, mon, page, query, agg_impr, avg_pos, 
                                                    country, device, ttype, tld)
          SELECT extract(year from date) as yr, extract(month from date) as mon,
          page, query, sum(impressions) as agg_impr, avg(position) as avg_pos, 
          @country_temp, @device_temp, @ttype_temp, @tld_temp
          FROM oldTable g
          WHERE g.device = @device_temp
          AND g.page LIKE @url
          AND g.country = @country
          group by page, query, extract(year from date), extract(month from date)
          order by yr, mon;
          SET @counter = @counter + 1;
      END LOOP;
  END
  </code></pre>
  <p>You can check the error message in the link below:
  <a href="https://i.stack.imgur.com/s0oKl.jpg" rel="nofollow noreferrer">Error message from DBeaver</a></p>
  <p>Also to be more detailed. The oldTable has various dimensions (country, tld, device, etc.) and metrics (impressions, clicks, etc.) from organic data (Google Search Console). I need to be able to input the desired variations of specific dimensions to the tempTable and the script fetch these row by row as parameters, retrieve the respective data from the oldTable, do some calculations and push the calculated data to the newTable.</p>
  <p>i.e.
  <strong>tempTable</strong>
  [ident country device]
  1     france  mobile,
  2     france  desktop,
  3     germany mobile</p>
  <p>the script iterates the tempTable and uses the values of each row as parameters to select the respective data from oldTable.</p>