MySQL存储过程错误 [英] Mysql stored procedure error

查看:115
本文介绍了MySQL存储过程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下存储过程添加到我的mysql数据库中:

I'm trying to add the following stored procedure to my mysql database:

CREATE PROCEDURE logmsg ( _Username VARCHAR(50), _Message VARCHAR(80) )
BEGIN 
    INSERT INTO chatlogs (sender, message) VALUES (_Username, _Message);
END;

但是查询失败并返回:

#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 '' at line 3 

我在Google上搜索了大约2个小时,根本找不到任何答案.

I've been searching for about 2 hours on google and cannot find any answer at all.

任何帮助将不胜感激!

推荐答案

虽然我不确定100%因为目前无法在MySQL服务器上进行测试,但我认为问题出在分号上.在INSERT行中,您基本上结束了CREATE PROCEDURE语句,这种语句的语法不正确.您必须将定界符设置为其他内容(例如//),以便能够在过程主体中使用分号:

While I'm not 100% sure because I can't test on a MySQL server at the moment, I think the problem is in the semicolon. On the line with INSERT you basically end the CREATE PROCEDURE statement, which has incorrect syntax this way. You have to set the delimiter to something else (e.g. //), to be able to use the semicolon in the body of the procedure:

delimiter //

CREATE PROCEDURE logmsg ( _Username VARCHAR(50), _Message VARCHAR(80) )
BEGIN 
    INSERT INTO chatlogs (sender, message) VALUES (_Username, _Message);
END//

delimiter ;

这篇关于MySQL存储过程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆