CREATE PROCEDURE test()
BEGIN
DECLARE fid int;
DECLARE days int DEFAULT 1;
DECLARE s int default 0;
DECLARE company_code VARCHAR;
DECLARE cursor_company CURSOR FOR SELECT company FROM test WHERE status = 3;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET a=1;
OPEN cursor_company;
FETCH cursor_company INTO company_code;
WHILE a<>1 DO
IF company_code = 'DD' THEN
SET days = 2;
END IF;
ELSEIF company_code ='ZD' THEN
SET days = 5;
END ELSEIF;
ELSEIF company_code ='GG' THEN
SET days = '8';
END ELSEIF;
FETCH cursor_company INTO company_code;
DECLARE cursor_name CURSOR FOR SELECT id FROM test WHERE UNIX_TIMESTAMP(check_time) < UNIX_TIMESTAMP(DATE_ADD(NOW(),INTERVAL -days DAY));
#设置一个终止标记
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s=1;
#打开游标
OPEN cursor_name;
#获取游标当前指针的记录,读取一行数据并传给变量stu
FETCH cursor_name INTO fid;
#开始循环,判断是否游标已经到达了最后作为循环条件
WHILE s <> 1 do
UPDATE test SET status = 8 where id=fid;
#读取下一行的数据
FETCH cursor_name INTO fid;
END WHILE;
#关闭游标
CLOSE cursor_name ;
#语句执行结束
END WHILE;
CLOSE cursor_company;
END
表结构
id int
check_time datetime
status int
company varchar
错误信息:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
DECLARE cursor_company CURSOR FOR SELECT company FROM test WHERE status =' at line 10
看了好久,可是感觉没有错误,不知道毛病出在哪里,求大神解答