我在执行下面的脚本提及时遇到错误
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'$$
GKCHGYEGRGFQGRHYEGRSDGPNGQL 56
WGCGGYESRGFQGRHYEGGGDCPNGQG 56
GLCCGYEGRGFQCRHYEGGGDGPNDQL 56
GKGCGYEGRGFQGRHYEHGIDKDHFFR 43
PYGSGGNRARRSGCSWMLYEQVNYSGD 25
DFTEDLRCLQDVFAFNEIVSLNVLERL 25
REDYRRQSIYELSNYRCRQYLTDPSDY 24
答案 0 :(得分:1)
在创建程序之前缺少DELIMITER
DELIMITER $$
DROP PROCEDURE IF EXISTS `GetTopParentGivenDepth`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetTopParentGivenDepth`(GivenDepth INT)
BEGIN
DECLARE X,Y,x1,x2 INT;
SET X = 0;
SET Y = 1;
SET @SQ = 'SELECT DISTINCT A0.id FROM categories A0';
WHILE Y < GivenDepth DO
SET @SQ = CONCAT(@SQ,' INNER JOIN categories A',Y,' ON A',X,'.id = A',Y,'.parent_id');
SET X = Y;
SET Y = X + 1;
END WHILE;
SET @SQ = CONCAT(@SQ,' WHERE A0.parent_id = 0');
SELECT @SQ;
PREPARE stmt FROM @SQ;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;