简体   繁体   English

MySQL存储过程错误

[英]mySQL stored procedure error

I am trying to use a if statement in my stored mySQL procedure, but when I try to create it in mySQL workbench I get this 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 'database'.'table' WHERE date=dateIn; 我试图在存储的mySQL过程中使用if语句,但是当我尝试在mySQL工作台中创建它时,出现此错误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 'database'.'table' WHERE date=dateIn; 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 'database'.'table' WHERE date=dateIn; .

Here is the code: 这是代码:

DELIMITER $$

CREATE DEFINER=`rates_d_db` PROCEDURE `byDate`(in dateIn VARCHAR(255),in action VARCHAR(255))
BEGIN

IF action = "edit" THEN EDIT `database`.`table` WHERE date=dateIn;

ELSE SELECT * FROM `database`.`table` WHERE date=dateIn;

END IF;

END$$

I am new to stored procedures, so it's probably a very noob mistake. 我是存储过程的新手,所以这可能是一个非常愚蠢的错误。

Thanx in advance! 提前感谢!

Here is correct version of your procedure 这是您程序的正确版本

DELIMITER $$

CREATE DEFINER=`rates_d_db` PROCEDURE `byDatee`(in dateIn VARCHAR(255),in action VARCHAR(255))
       BEGIN
           IF action = "edit" THEN 
                -- I used select below as i don't know what you want in edit either alter table or update table
               SELECT * FROM `database`.`table` WHERE date=dateIn;    
           ELSE
                SELECT * FROM `database`.`table` WHERE date=dateIn;
           END IF;
END $$

date is a reserved word in mySQL. date是mySQL中的保留字 You will have to wrap that in backticks as well. 您还必须将其包装在反引号中。

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

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