我已經開始使用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語法編寫的。 –