Home > Database > Mysql Tutorial > body text

mysql cursor usage template

大家讲道理
Release: 2016-11-12 10:30:14
Original
1124 people have browsed it

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;
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template