gpt4 book ai didi

mysql - SQL 语法错误。创建存储过程

转载 作者:行者123 更新时间:2023-11-29 01:39:08 24 4
gpt4 key购买 nike

我已经开始使用 MySQL 创建一个存储过程。然后我想进行 migration:up (MyBatis)。

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

执行 migration:up 命令后

我收到一个错误

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

最佳答案

你应该改变'分隔符'

DROP PROCEDURE IF EXISTS add_tips;

delimiter //


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 //

delimiter ;

关于mysql - SQL 语法错误。创建存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30708704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com