mysql 中使用存储过程
2008-03-07 12:52
344 查看
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
相关文章推荐
- PHP使用ADODB调用MySQL存储过程
- mysql存储过程 游标 循环使用 含SQLSTATE mysql异常代码汇总大全
- mysql存储过程 游标 循环使用介绍
- MySQL使用mysqldump命令导入数据库时包含存储过程
- MySQL存储过程使用表名做参数
- MySQL 存储过程传參之in, out, inout 參数使用方法
- mysql使用存储过程制造测试数据
- mysql 触发器和存储过程组合使用,实现定时触发操作
- MySQL使用存储过程插入千万级数据
- 使用Mysql 存储过程,批量插入100万条数据
- mysql 使用存储过程分割字符串利用循环插入数据
- 什么时候使用mysql 存储过程
- mysql使用存储过程生成大量数据
- Mysql多行插入,不使用存储过程
- MySQL笔记---视图,存储过程, 触发器的使用入门
- mysql 使用游标进行删除操作的存储过程
- MySQL 使用存储过程实现留存率
- mysql 存储过程、游标及逐行处理的配合使用
- MySQL,Oracle,DB2使用存储过程插入大数据
- Mysql存储过程------存储过程的基本概念和基本使用方法