简体   繁体   English

无法创建MySQL过程来更新表

[英]Can't create MySQL procedure to update table

I am trying to make a procedure to update an existing user. 我正在尝试制定一个程序来更新现有用户。 It receives the name of the user and then increments his points column. 它接收用户名,然后增加其积分栏。 I have it like this: 我有这样的:

CREATE PROCEDURE addPoints (IN nomeus varchar(20))

BEGIN  

UPDATE User
   SET
       points=points+1
   WHERE (nome=nomeus) ;

END;

However, I get this error: 但是,我收到此错误:

#1064 - You have an error in your SQL syntax; #1064-您的SQL语法有误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 8 检查与您的MariaDB服务器版本相对应的手册以在第8行的''附近使用正确的语法

How can I fix it? 我该如何解决?

Yeah, I had to use delimiters: 是的,我必须使用定界符:

delimiter //
CREATE PROCEDURE addPoints(IN nomeuser varchar(256)) 
BEGIN  
    UPDATE User
  SET
      points = points + 1
  WHERE nome = nomeuser; 
 END;//
delimiter ;

When in doubt just go to dev.mysql they have some great documentation there. 如有疑问,请访问dev.mysql,那里有一些不错的文档。

http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

Looks like you found the answer to your own question. 看起来您找到了自己问题的答案。 However, if you change any of the code in the procedure, don't forget to drop the procedure before trying to create it again. 但是,如果您更改了过程中的任何代码,请不要忘记先删除该过程再尝试再次创建它。

Drop Procedure if exists addPoints;

http://dev.mysql.com/doc/refman/5.0/en/drop-procedure.html http://dev.mysql.com/doc/refman/5.0/en/drop-procedure.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM