DELIMITER $$

USE `you`$$

DROP PROCEDURE IF EXISTS `stockCursor`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `stockCursor`()
BEGIN  
    DECLARE change_id VARCHAR(40);
    DECLARE flag INT DEFAULT 0;
    DECLARE stock_cursor CURSOR FOR SELECT `order_id` FROM `ts_order` ;
       DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1;
        OPEN stock_cursor;
         /*循环*/
         REPEAT  
          FETCH stock_cursor INTO change_id;
           /*判断防止多执行最后一次*/
           IF flag=0 THEN 
             INSERT INTO test(`order_id`) VALUES(change_id);
           END IF;
         UNTIL flag 
         END REPEAT;
    CLOSE stock_cursor ;
END$$

DELIMITER ;