mysql 使用 if 退出 sp
mysql exit sp with if
在下面的 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
14.6.6.2 Cursor DECLARE
Syntax
...
Cursor declarations must appear before handler declarations and
after variable and condition declarations.
...
...
/*
-- 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;
...
在下面的 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
14.6.6.2 Cursor DECLARE Syntax
...
Cursor declarations must appear before handler declarations and after variable and condition declarations.
...
...
/*
-- 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;
...