DROP PROCEDURE if EXISTS test;
delimiter $$
CREATE PROCEDURE test()
BEGIN
set @startTime = CURRENT_TIMESTAMP;
select @diff = TIMESTAMPDIFF(MINUTE ,end_time,CURRENT_TIMESTAMP) from table_name order by end_time desc limit 1;
set @endTime;
IF @diff>10 THEN
@endTime = DATE_SUB(@startTime,INTERVAL @diff MINUTE);
ELSE
@endTime = DATE_SUB(@startTime,INTERVAL 10 MINUTE);
END IF;
select concat('startTime is ', @startTime),concat('endTime is ', @endTime);
END
delimiter ;
求大神指点一下,这个存储过程有什么问题呀,一直编译不过去,错误信息如下:
[Err] 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 ';
IF @diff>10 THEN
@endTime = DATE_SUB(@startTime,INTERVAL @diff MINUTE);' at line 5
table_name的建表语句
CREATE TABLE table_name(
id BIGINT(64) AUTO_INCREMENT,
start_time TIMESTAMP NULL DEFAULT NULL COMMENT '开始查询时间',
end_time TIMESTAMP NULL DEFAULT NULL COMMENT '结束查询时间',
create_time TIMESTAMP NULL DEFAULT NULL COMMENT '创建时间',
update_time TIMESTAMP NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (id)
) ENGINE=InnoDB CHARSET=utf8;