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 whe
·
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;
参考:http://dev.mysql.com/doc/refman/5.1/zh/stored-procedures.html#declare-cursors
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;
参考:http://dev.mysql.com/doc/refman/5.1/zh/stored-procedures.html#declare-cursors
更多推荐
所有评论(0)