mysql存储过程实例一:游标的使用
DROP PROCEDURE IF EXISTS `doProcessPersonURL`$$
CREATE PROCEDURE `doProcessPersonURL`()
BEGIN
DECLARE fig INT;/*申明int变量*/
DECLARE iResult INT DEFAULT 0;/*申明int变量,并赋初值*/
DECLARE personurl VARCHAR(50) DEFAULT NULL;
DECLARE spaceid VARCHAR(50) DEFAULT NULL;
DECLARE cur CURSOR FOR SELECT personal_url,id FROM tables_a;/*申明游标*/
DECLARE EXIT HANDLER FOR NOT FOUND SET fig=1;/*没有数据不执行*/
#DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET fig =0;
OPEN cur;/*打开游标*/
REPEAT/*循环*/
FETCH cur INTO personurl, spaceid; /*将游标里面的值赋给a*/
SELECT personurl REGEXP '^[0-9]*$' INTO iResult;/*判断个性网址是否为纯数:1-为纯数字 0-非纯数字*/
IF (iResult = 1) THEN
UPDATE tables_a SET personal_url=NULL WHERE id=spaceid;
END IF;
UNTIL fig = 1
END REPEAT ;
CLOSE cur;
# COMMITTED;
END$$
正文到此结束