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

时间:2014-10-21 07:01:42

标签: mysql stored-procedures

我试图运行以下查询,但是当我尝试这样做时,它会出现以下错误

  

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'SET @tab = CONCAT(“monitorTable _”,ir)附近使用正确的语法;

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 ;

1 个答案:

答案 0 :(得分:0)

请注意,BEGIN - END阻止不能独立存在。 您的代码中缺少Create procedure语句,之后应包含BEGIN - END块。

delimiter $$

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

$$

delimiter ;