创建过程失败?
当尝试在 mysql 5.1.47-community 中创建一个简单的过程时,每次我尝试了所有方法都会失败! 即使是这样简单的事情!
DELIMITER //
CREATE PROCEDURE two ()
begin
SELECT 1+1;
end;
//
错误是
错误:错误 1064:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“mydb”附近使用的正确语法
when trying to create a simple procedure in mysql 5.1.47-community it fails everytime i've tried everything!
even simple things like this!
DELIMITER //
CREATE PROCEDURE two ()
begin
SELECT 1+1;
end;
//
The error is
ERROR: Error 1064: 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 'mydb' at line 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您提供的错误消息与您粘贴的代码不对应。您在运行的 SQL 中的某个位置引用了“mydb”,但它不在您放入问题的代码中的任何位置。
您给出的代码应该可以正常工作,因为我没有看到任何语法错误,您可能只需要给它一个可以使用的数据库(在我的例子中为“
test
”,也许应该是“< code>mydb”适合你吗?)。但是,我怀疑您遇到的错误是您没有向我们展示的 SQL 中的一行。
编辑
它可能是
delimiter
命令。您要将分隔符更改为//
而不是默认的;
。因此,也许您已经运行了该命令(并将会话的分隔符更改为 //),然后尝试运行USE mydb;
,其中;
不再被识别作为会话的有效分隔符,这可能会给您带来错误。尝试在 use 行之前放置delimiter ;
并查看是否有帮助(然后在定义存储过程后再次使用它,以便可以调用它)。但这只是一个理论,因为我不确定分隔符命令的复杂性。The error message you've given doesn't correspond to the code you've pasted. You're referring to "mydb" somewhere in the SQL you're running yet it's not anywhere in the code you've put in the question.
The code you've given should work fine as I see no syntax errors, you may just need to give it a database to work on ("
test
" in my case here, perhaps it should be "mydb
" for you?).However, I suspect the error you're getting is become of a line in your SQL that you're not showing us.
EDIT
It could perhaps be the
delimiter
command. You're changing the delimiter to//
rather than the default;
. So perhaps you've run that command (and changed the delimiter for your session to //), and then tried to runUSE mydb;
where the;
is no longer recognised as a valid delimiter for your session, and that could be giving you the error. Try puttingdelimiter ;
before your use line and see if that helps (and then use it again after you've defined your stored procedure so you can call it). This is just a theory though, as I'm not sure of the intricacies of the delimiter command.删除最后的分隔符“end”而不是“end;”
Remove the final delimiter "end" instead "end;"
我使用 heidisql 作为输入 SQL 的前端时遇到了同样的问题。我的第一次尝试是:
这导致了
SQL ERROR (1064)
因为我不知道在使用客户端程序时 分隔符需要 定义存储过程。将上面的内容更改为:
成功了。
调用它的示例
I had the same problem using heidisql as the fronted to enter the SQL. My first attempt was:
and this resulted in
SQL ERROR (1064)
because i was not aware that when using a client program a delimiter is needed to define the stored procedures.After changing the above to this:
It worked out.
Example to call it