Error in the procedure

Asked

Viewed 79 times

1

I’m new to creating PROCEDURE. I am trying to create this PROCEDURE plus this tando error.

DELIMITER //

DROP PROCEDURE IF EXISTS `P_lgs`;
CREATE PROCEDURE `P_lgs` ( idcod INT, dt VARCHAR(20), ip VARCHAR(20), msg VARCHAR(250), mail VARCHAR(250) ) 
BEGIN
  DECLARE numid INT DEFAULT 0;
  IF idcol <> 0 THEN 
    numid = idcol;
  END IF ;

  INSERT INTO `logs`(logs_cod,logs_dt,logs_ip,logs_mensagem,logs_email) VALUE(numid,dt,ip,msg,mail);
END //

DELIMITER ;
  • 1

    Which error? In which section?

  • You’d better read the documentation: https://dev.mysql.com/doc/refman/5.1/en/stored-programs-defining.html

  • @gmsantos error is on line create Procedure,

  • Query: drop Procedure if exists P_lgs; create Procedure P_lgs ( idcod int, dt varchar(20), ip varchar(20), msg varchar(250), mail v... Error Code: 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 'create Procedure P_lgs ( idcod int, dt varchar(20), ip varchar(20), msg varcha' at line 2

  • @Welguri Before Creating The Future Again You Need To Drop The Old...

  • @gmsantos more before the CREATE PROCEDURE, I put the DROP.

  • @Welguri but with the delimiter ; old. Try changing the delimiter to DROP PROCEDURE IF EXISTS P_lgs//

Show 2 more comments

2 answers

1

@Welguri, try it like this:

 BEGIN
  DECLARE numid INT DEFAULT 0
  IF idcol <> 0 THEN 
    numid = idcol

INSERT INTO `logs`(logs_cod,logs_dt,logs_ip,logs_mensagem,logs_email) VALUE(numid,dt,ip,msg,mail)
END //
  • The error is happening on the line, CREATE PROCEDURE... Error Code: 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 'create Procedure P_lgs ( idcod int, dt varchar(20), ip varchar(20), msg varcha' at line 2

1

In this way nay there were more error.

DELIMITER //

DROP PROCEDURE IF EXISTS P_lgs;//
CREATE PROCEDURE P_lgs ( IN idcod INT, IN dt VARCHAR(20), IN ip VARCHAR(20), IN msg VARCHAR(250), IN mail VARCHAR(250) ) 
BEGIN
  DECLARE numID INT DEFAULT 0;
  IF idcol = '' THEN 
    SELECT numID=0;
  ELSE
    SELECT numID=idcol;
  END IF;

  INSERT INTO LOGS(logs_cod, logs_dt, logs_ip, logs_mensagem, logs_email) VALUES(numID, dt, ip, msg, mail);
END //

DELIMITER ;
  • The only difference is the drop delimiter ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.