gpt4 book ai didi

mysql - MySql 过程中的 DECLARE 变量错误

转载 作者:搜寻专家 更新时间:2023-10-30 23:07:44 25 4
gpt4 key购买 nike

我正在尝试创建一个像这样的简单存储过程:

CREATE DEFINER = 'root'@'localhost'
PROCEDURE testProcedure()
BEGIN

DECLARE variableAaa INT;
DECLARE variableBbb INT;

END

但是我从 MySql 得到这个错误:

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 'END' at line 1

如果我更改变量名称:

DECLARE variableA INT;
DECLARE variableB INT;

我得到错误:

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 variableB INT' at line 1

等等:

DECLARE variableName INT;
DECLARE variableEmail INT;

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 variableEmail INT' at line 1

我将 MySql 5.5.34 与 PhpMyAdmin 一起使用,但它与 Sequel Pro 相同。

我哪里错了?

最佳答案

看起来它是您缺少的定界符问题

所以程序应该是这样的

delimiter //
CREATE DEFINER = 'root'@'localhost'
PROCEDURE testProcedure()
BEGIN

DECLARE variableAaa INT;
DECLARE variableBbb INT;

END ; //

delimiter ;

这里我在 MySql 上尝试了同样的方法,它有效

mysql> delimiter //
mysql> create procedure testProcedure()
-> begin
-> DECLARE variableAaa INT;
-> DECLARE variableBbb INT;
-> end; //
Query OK, 0 rows affected (0.02 sec)

mysql> delimiter ;

关于mysql - MySql 过程中的 DECLARE 变量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24349684/

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