Home >Database >Mysql Tutorial >mysql cursor usage template

mysql cursor usage template

大家讲道理
大家讲道理Original
2016-11-12 10:30:141144browse

BEGIN 
   /**  
     *   
     * 游标模版  
     * @author xuyw  
     * @email xyw10000@163.com  
     * @date 2014-05-19  
     */  
     /*游标数据变量 uid*/  
    DECLARE uid VARCHAR(128);  
    DECLARE done INT DEFAULT 0;  
       
    /*查询所有用户*/  
    DECLARE cur CURSOR FOR SELECT xxx FROM xx;  
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;  
  OPEN cur;  
    /* 开始循环*/  
    REPEAT  
    /* 提取游标里的数据*/  
    FETCH cur INTO uid;  
    IF done =0 THEN  
    执行你的业务  
   END IF;  
  UNTIL done=1  
  END REPEAT;  
  /*关闭游标*/  
  CLOSE cur;  
END;

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