title: MySql stored procedure error [ERROR 1338 (42000): Cursor declaration after handler declaration]
body: <p>I am reading an article on stored procedures and this is the code:</p>
  
  <pre><code>delimiter //
  
  create procedure largest_order(out largest_id int) 
  begin
    declare this_id int;
    declare this_amount float;
    declare l_amount float default 0.0;
    declare l_id int;
  
    declare done int default 0;
    declare continue handler for sqlstate '02000' set done = 1;
    declare c1 cursor for select orderid, amount from orders;
  
    open c1;
    repeat
      fetch c1 into this_id, this_amount;
      if not done then
        if this_amount &gt; l_amount then
          set l_amount=this_amount;
          set l_id=this_id;
        end if;
      end if;
     until done end repeat; 
    close c1;
  
    set largest_id=l_id;
  
  end
  //
  
  delimiter ;
  </code></pre>
  
  <p>I am using a simple database named "mydatabase". After running the above code it gives me this error: <code>ERROR 1338 (42000): Cursor declaration after handler declaration</code>
  What is wrong and how can I fix it?</p>
  
  <p>This is my first time working with stored procedures.</p>