Home  >  Article  >  Database  >  MySQL游标循环示例_MySQL

MySQL游标循环示例_MySQL

WBOY
WBOYOriginal
2016-06-01 13:38:10959browse

bitsCN.com


MySQL游标循环示例

 

如果用in语句,感觉很慢,跑了好久都没有结果,用存储过程删除可以把握

进度,这个是MySQL游标循环的示例代码,避免以后经常找,记录上来。

   

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

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn