mysql存储:mysql 中使用存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `curdemo`()
BEGIN

  DECLARE done INT DEFAULT 0;

  DECLARE userid,repid  INT;

  DECLARE cur1 CURSOR FOR select u.userid,u.repid from user u,personalwebsite p where
  p.url <> u.repid and p.distributorid = u.userid
  and p.url = u.userid;

  DECLARE CONTINUE HANDLER FOR SQLSTATE \'02000\' SET done = 1;
 
  OPEN cur1;

 
  REPEAT

    FETCH cur1 INTO userid,repid;
 
    IF NOT done THEN

       update personalwebsite set url = repid where distributorid = userid;

    END IF;

  UNTIL done END REPEAT;

  CLOSE cur1;

END;  
0
- 返回顶部
Copyright 2003-2008 www.Zxbc.cn All Rights Reserved
湘ICP备07001293号 E-mail:[email protected]
中国自学编程网版权所有,禁止转载!
Tags:  mysql存储

延伸阅读

最新评论

发表评论