How to skip to next iteration if no results are returned in SELECT statement in Stored Procedure I have a case where I SELECT rows from one table and INSERT them to another table. However, I get Error: 1329 SQLSTATE: 02000 if the SELECT statement doesn't return any row. Can I do something like:

CREATE PROCEDURE SP()
   DECLARE CONTINUE HANDLER FOR NOT FOUND;
   BEGIN
      ITERATE
   END
   BEGIN 
      DECLARE cur1 CURSOR FOR SELECT * FROM table1;
      OPEN cur1; 
      read_loop: LOOP
         FETCH cur1 INTO var1;
         INSERT INTO table2 (SELECT c1 FROM table3)
      END LOOP;
      CLOSE cur1;
   END;


Is this correct? Thanks.

EDIT:

Based on answers below, what worked for me was:

BEGIN
    DECLARE done BIT DEFAULT FALSE; 
    DECLARE name VARCHAR(255);
    DECLARE lat FLOAT;
    DECLARE lon FLOAT;
    DECLARE radius FLOAT;
    DECLARE cur1 CURSOR FOR SELECT * FROM anchorage_test;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
    OPEN cur1; 
    read_loop: LOOP
       SET done = FALSE;
       FETCH cur1 INTO name, lat, lon, radius;
       IF done THEN
          LEAVE read_loop;
       END IF;
       INSERT INTO sp_result
       SELECT imo, draught, ST_Distance_Sphere(point(lon, lat),point(longitude,latitude))*0.000539957 AS distance, dt_pos_utc, name FROM historical_temp HAVING distance &lt; radius;
    END LOOP;
    CLOSE cur1;
END
You shoud use: LEAVE loop_name

IF NOT EXIST (SELECT 1 FROM table3 WHERE &lt;some condition&gt;)
    LEAVE read_loop;