简体   繁体   中英

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; 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. You will have to wrap that in backticks as well.

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