MySQL游標循環示例
如果用in語句,感覺很慢,跑了好久都沒有結果,用存儲過程刪除可以把握
進度,這個是MySQL游標循環的示例代碼,避免以後經常找,記錄上來。
www.2cto.com
CREATE DEFINER=`root`@`%` PROCEDURE `bi`.`clean_data`()
READS SQL DATA
BEGIN
declare v_imei varchar(128);
declare stop int default 0;
declare cur cursor for (select imei from bi.tmp_imei);
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop=1;
OPEN cur;
FETCH cur INTO v_imei;
WHILE stop <> 1 DO
delete from bi.tmp_dt_fee_user_info where imei=v_imei;
FETCH cur INTO v_imei;
END WHILE;
CLOSE cur;
END