在msql sp下面我试图退出,如果星期几是星期五,但我不能让它工作,因为接缝是“END IF”的语法错误我只是看不到它。
CREATE PROCEDURE `bookFreeDay`()
proc_label:BEGIN
DECLARE bDone INT;
DECLARE t1 VARCHAR(5);
-- todo exclude sa/so
IF DAYOFWEEK(SUBDATE(CURDATE(),1)) = 5 THEN
LEAVE proc_label;
END IF;
DECLARE curs CURSOR FOR select durTime from freeDays where
(year is not null && year= substring(CURDATE(),1,4) && start=substring(SUBDATE(CURDATE(),1), 6,5))
|| (year is null && start=substring(SUBDATE(CURDATE(),1), 6,5));
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
OPEN curs;
SET bDone = 0;
REPEAT
FETCH curs INTO t1;
select CONCAT(SUBDATE(CURDATE(),1), " 08:00:00") into @st;
select addtime(@st, t1) into @en;
insert into timeEntries
(select
null,
idUsers,
@st,
@en,
null,
2
from users
where right(pensum,1)='%');
UNTIL bDone END REPEAT;
CLOSE curs;
END
答案 0 :(得分:0)
14.6.6.2 Cursor DECLARE Syntax
...
游标声明必须出现在处理程序声明之前 在变量和条件声明之后。
...
...
/*
-- todo exclude sa/so
IF DAYOFWEEK(SUBDATE(CURDATE(),1)) = 5 THEN
LEAVE proc_label;
END IF;
*/
DECLARE curs CURSOR FOR select durTime
from freeDays
where (year is not null &&
year= substring(CURDATE(),1,4) &&
start=substring(SUBDATE(CURDATE(),1), 6,5)) ||
(year is null &&
start=substring(SUBDATE(CURDATE(),1), 6,5));
DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
-- todo exclude sa/so
IF DAYOFWEEK(SUBDATE(CURDATE(),1)) = 5 THEN
LEAVE proc_label;
END IF;
...