gpt4 book ai didi

MYSQL 语法错误,意外的 while_sym,期待 END_OF_INPUT 或 ';'

转载 作者:行者123 更新时间:2023-11-29 02:54:52 24 4
gpt4 key购买 nike

我正在尝试创建一个存档事件,我想出的结果如下所示:

SET @Date = NULL;
SET @SEDOL = NULL;
CREATE EVENT IF NOT EXISTS Archive_Event
ON SCHEDULE EVERY 1 DAY
DO
SELECT @Date = Date,@SEDOL = SEDOL
from daily.analytics
where Date = (SELECT MIN(Date)
from daily.analytics
WHERE Date < date_sub(NOW(), INTERVAL 21 DAY))
order by SEDOL desc limit 1

WHILE @date is not null
begin
begin transaction
-- Adds old line to archive
insert into daily.Archive_analytics
select * from daily.analytics where Date = @Date AND SEDOL = @SEDOL
-- Deletes old line from main table
delete from daily.analytics where Date = @Date AND SEDOL = @SEDOL
commit transaction
-- Find the next greater minimum value
SELECT @Date = Date,@SEDOL = SEDOL
from daily.analytics
where Date = (SELECT MIN(Date)
from daily.analytics
WHERE Date < date_sub(NOW(), INTERVAL 21 DAY))
order by SEDOL desc
limit 1
END WHILE
END

在网上搜索这似乎或多或少是正确的,但是我的 WHILE 语句出现“语法错误,意外的 while_sym,期待 END_OF_INPUT 或‘;’”,我不太清楚为什么。

非常感谢任何帮助。

最佳答案

原来问题是由于分隔符和代码中的多个 block 引起的。没有语法错误的版本如下所示:

SET @Date = NULL;
SET @SEDOL = NULL;

delimiter |
CREATE EVENT IF NOT EXISTS daily.Archive_Event_HOUR
ON SCHEDULE EVERY 1 DAY
DO
begin
SELECT @Date = Date,@SEDOL = SEDOL
from daily.analytics
where Date = (SELECT MIN(Date)
from daily.analytics
WHERE Date < date_sub(NOW(), INTERVAL 21 DAY))
order by SEDOL desc limit 1;

WHILE @Date is not null DO
start transaction;
-- Adds old line to archive
insert into daily.Archive_analytics
select * from daily.analytics where Date = @Date AND SEDOL = @SEDOL;
-- Deletes old line from main table
delete from daily.analytics where Date = @Date AND SEDOL = @SEDOL;
commit;
-- Find the next greater minimum value
SELECT @Date = Date,@SEDOL = SEDOL
from daily.analytics
where Date = (SELECT MIN(Date)
from daily.analytics
WHERE Date < date_sub(NOW(), INTERVAL 21 DAY))
order by SEDOL desc
limit 1;
END WHILE;
END|
delimiter ;

关于MYSQL 语法错误,意外的 while_sym,期待 END_OF_INPUT 或 ';',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31653345/

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