我一直在为这个问题伤脑筋。目前还找不到任何答案,所以如果有人能帮助我,我将不胜感激!
以下查询会导致 suntax 错误。知道出了什么问题吗?
BEGIN
DECLARE cur CURSOR FOR
SELECT * FROM objects
WHERE present_in_last_scrape = FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
DECLARE done INT DEFAULT 0;
read_loop: LOOP
FETCH cur INTO record;
IF done THEN
LEAVE read_loop;
END IF;
UPDATE lifetimes SET end_time=extract(epoch from now()) WHERE object_id=record.object_id AND end_time IS NULL;
END LOOP;
CLOSE cur;
END
语法错误:
SQL Error [1064] [42000]: 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 'DECLARE cur CURSOR FOR
SELECT * FROM objects
WHERE present_in_last_scrap' at line 2
SQL Error [1064] [42000]: 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 'DECLARE cur CURSOR FOR
SELECT * FROM objects
WHERE present_in_last_scrap' at line 2
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 'DECLARE cur CURSOR FOR
SELECT * FROM objects
WHERE present_in_last_scrap' at line 2
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 'DECLARE cur CURSOR FOR
SELECT * FROM objects
WHERE present_in_last_scrap' at line 2
最佳答案
谢谢大家的帮助! epoch 的东西确实是 postgresql,已经改变了。 @solarflare 的 create_procedure 评论是正确的,最终成功了!
CREATE PROCEDURE set_end_time (out done int)
BEGIN
DECLARE cur CURSOR FOR
SELECT * FROM objects
WHERE present_in_last_scrape = FALSE;
OPEN cur;
LOOP
UPDATE lifetimes SET end_time=UNIX_TIMESTAMP(NOW()) WHERE hemnet_id=cur.hemnet_id AND end_time IS NULL;
END LOOP;
CLOSE cur;
END
关于mysql - SQL游标语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41282832/