您的位置:首页 > 数据库 > MySQL

mysql 中使用存储过程

2008-03-07 12:52 288 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: