我已经开始使用MySQL创建存储过程。 然后我想进行迁移:up(MyBatis)。SQL语法错误。创建存储过程
mvn migration:up -Dmigration.path=/path/to/repository
这里是我的存储过程
DROP PROCEDURE IF EXISTS add_tips;
CREATE DEFINER=`root`@`localhost` PROCEDURE `add_tips`(gspId INTEGER, gameID INTEGER)
BEGIN
DECLARE @start_datetime = getdate();
DECLARE @execution_time_in_seconds int;
DECLARE @LID int;
INSERT INTO sp_logs(spName, startTime) VALUES(`add_tips`, @start_datetime);
SET @LID = LAST_INSERT_ID();
...
/*some code goes here*/
...
@execution_time_in_seconds = datediff(SECOND,@start_datetime,getdate())
UPDATE sp_logs
SET executionTime = @execution_time_in_seconds
WHERE logId = @LID;
END
之后迁移:最高命令执行
我收到一个错误
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
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 '@start_datetime = getdate();
[INFO] DECLARE @execution_time_in_seconds int;
[INFO] DECLARE @LI' at line 4
你正在使用奇单引号。删除它们并使用标准单引号'而不是' – CathalMF
毫无疑问,您正在收到语法错误。您的存储过程是在许多地方使用SQL Sever语法编写的。 –