简体   繁体   中英

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; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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