gpt4 book ai didi

mysql 退出 sp 与 if

转载 作者:行者123 更新时间:2023-11-29 19:31:23 25 4
gpt4 key购买 nike

在下面的 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;

...

关于mysql 退出 sp 与 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41754719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com