gpt4 book ai didi

mysql - mysql 中 ELSE IF block 中的游标声明?

转载 作者:行者123 更新时间:2023-11-29 01:27:35 25 4
gpt4 key购买 nike

我想知道,我们可以在 ELSE IF block 中声明游标吗?当我这样做时,我发现错误在“声明”之前缺少子句或其他元素。我的代码是

 if State is NOT NULL
then
declare t cursor for select *from student;//this line has error
declare continue handler for NOT FOUND set str=1;
else
declare t cursor for select *from student;
end if;

为什么??

最佳答案

答案是manual明确地说:

Cursor declarations must appear before handler declarations and after variable and condition declarations.

类似[bug: 15809] (最终不是)被报告但它以以下答案关闭:

Thank you for a problem report. Sorry, but I do not think it is a bug. The problem is that cursor should be declared, and all declarations are at the beggining of SP or a block.

Please, read (http://dev.mysql.com/doc/refman/5.0/en/cursors.html):

"Cursors must be declared before declaring handlers, and variables and conditions must be declared before declaring either cursors or handlers."

And, even more clearly (http://dev.mysql.com/doc/refman/5.0/en/declare.html):

"The DECLARE statement is used to define various items local to a routine: local variables (see Section 17.2.9, “Variables in Stored Procedures”), conditions and handlers (see Section 17.2.10, “Conditions and Handlers”) and cursors (see Section 17.2.11, “Cursors”). SIGNAL and RESIGNAL statements are not currently supported.

DECLARE may be used only inside a BEGIN ... END compound statement and must be at its start, before any other statements."

So, it is not a bug, but a documented behaviour.

关于mysql - mysql 中 ELSE IF block 中的游标声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34492124/

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