title: mysql cursor loop select
body: <p>I am writing a procedure which will go through a table and collect all the top 10 results. I am using a cursor then fetching the results. I'm a little stuck on how to print out the results. I used a select statement to get those results, but I'm told that there is an error. </p>
  
  <p>Any help will be appreciated. Thanks. </p>
  
  <pre><code>create procedure plant_list()
  begin
  declare v_plant_id integer(5);
  declare v_common_name varchar(30);
  declare v_scientific_name varchar(20);
  
  
  declare finished boolean default false;
  
  declare cur_top_ten cursor for
      select P.plant_id, common_name, concat(genus, ' ', species)
      from plants P
          join plant_taxonomy PT on P.plant_id = PT.plant_id
      order by list_price desc
      limit 10
      ;
  
  declare continue handler for not found set finished = true;
  
  open cur_top_ten;
  curloop: loop
      fetch cur_top_ten into v_plant_id, v_common_name, v_scientific_name;
      if finished then
          close cur_top_ten;
          set finished = false;
          leave curloop;
      end if
  
      select v_plant_id, v_common_name, v_scientific_name;
  
  
  end loop curloop;
  
  end;
  #
  </code></pre>