stored-procedures - 错误代码:1064不允许运行查询

  显示原文与译文双语对照的内容

我试图运行以下查询,但当我尝试执行它时,它会给出以下错误

你的SQL语法中有错误;请检查与你的MySQL服务器版本相对应的手册,以便在'设置 @tab = CONCAT ("monitortable_",红外) 附近使用。


DELIMITER $$

DROP PROCEDURE IF EXISTS `Modification`$$
BEGIN
 SET @tab = CONCAT("monitorTable_",pr);
 DROP TABLE IF EXISTS uniques;
 CREATE TEMPORARY TABLE uniques (`id` INT, `timestamp` DATETIME);
 SET @sqlstring = CONCAT("INSERT INTO uniques SELECT id,timestamp FROM",@tab," GROUP BY id");
 PREPARE stmt FROM @sqlstring;
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt;
 DROP TABLE IF EXISTS uniquescount;
 CREATE TEMPORARY TABLE uniquescount (`cnt` INT, `dat` DATETIME);
 INSERT INTO uniquescount SELECT COUNT(id) AS cnt, DATE(TIMESTAMP) AS dat FROM uniques GROUP BY DATE(TIMESTAMP);
 DROP TABLE IF EXISTS nonuniquescount;
 CREATE TEMPORARY TABLE nonuniquescount (`cnt` INT, `dat` DATETIME);
 SET @sqlstring = CONCAT("INSERT INTO nonuniquescount SELECT COUNT(id) AS cnt, DATE(TIMESTAMP) AS dat 
FROM",@tab," GROUP BY DATE(TIMESTAMP)");
 PREPARE stmt FROM @sqlstring;
 EXECUTE stmt;
 SELECT un.cnt AS ucnt, nu.cnt AS cnt, nu.dat AS dat FROM uniquescount un RIGHT JOIN nonuniquescount nu ON un.dat = nu.dat;
END$$

DELIMITER ;

时间: 作者:

请注意 BEGIN - END 块不能独立存在。 在代码中缺少 Create procedure 语句,在这里代码中应该包含 BEGIN - END 块。


delimiter $$

CREATE PROCEDURE Modification()
BEGIN
-- your code block here
END;

$$

delimiter ;

作者:
...