我正在尝试以块的形式从我的AWS RDS MySQL实例中删除大量数据。我正在尝试调整此link中的代码,但我遇到了无法修复的语法错误。
错误:
SET @apt = 'DTW';
SET @a = (SELECT MIN(operation_id) FROM operations_test);
BEGIN
main1: LOOP
SELECT @z := operation_id FROM operations_test WHERE operation_id >= @a ORDER BY operation_id LIMIT 1000,1;
IF @z IS NULL THEN
LEAVE main1; -- last chunk
END IF;
DELETE operations_test, profiles_test FROM profiles_test LEFT JOIN operations_test ON operations_test.operation_id=profiles_test.operation_id WHERE operations_test.airport_id = @apt
AND operations_test.operation_id >= @a
AND operations_test.operation_id < @z;
DELETE operations_test FROM operations_test WHERE airport_id = @apt
AND operation_id >= @a
AND operation_id < @z;
SET @a = @z;
SLEEP 1; -- be a nice guy, especially in replication
END LOOP main1;
END;
# Last chunk:
DELETE operations_test, profiles_test FROM profiles_test LEFT JOIN operations_test ON operations_test.operation_id=profiles_test.operation_id WHERE operations_test.airport_id = @apt
AND id >= @a;
DELETE operations_test FROM operations_test WHERE airport_id = @apt
AND id >= @a;
代码:
{{1}}
答案 0 :(得分:0)
Sorry, something went wrong. You may want to try again.
和BEGIN ... END
语句仅在MySQL存储程序的上下文中有效(例如LOOP
,PROCEDURE
,FUNCTION
,< / p>
作为使用示例:
TRIGGER
鉴于我们没有看到DELIMITER $$
CREATE PROCEDURE foo
BEGIN
SET ... ;
SET ... ;
myloop: LOOP
...
END LOOP myloop;
END$$
DELIMITER ;
语句,我们将猜测错误消息是将其作为裸语句执行的结果。语法错误是预期的结果。