我正在尝试创建一个存储函数,但是出现了一个让我发疯的错误,我真的不知道我的脚本有什么问题,我认为它没有错误,但我不知道为什么我收到此错误:
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'DECLARE cr1 CURSOR FOR SELECT codeArt, qte FROM LigneBonEntrée WHERE numBon = ' 附近使用的正确语法
这是我的脚本:
DELIMITER $$
CREATE DEFINER=root@localhost FUNCTION verifierQteDemandee(numBonIn INT) RETURNS BOOLEAN
BEGIN
DECLARE numLignesBonEntrée, numLignesBonSortie INTEGER;
DECLARE codeArtLigneBonEntrée, codeArtLigneBonSortie, qteLigneBonEntrée, qteLigneBonSortie INTEGER;
DECLARE no_more_rows BOOLEAN;
DECLARE qteArticle INTEGER;
DECLARE test BOOLEAN DEFAULT TRUE;
SET numLignesBonEntrée = (SELECT COUNT(*) FROM LigneBonEntrée WHERE numBon = numBonIn);
SET numLignesBonSortie = (SELECT COUNT(*) FROM numLignesBonSortie WHERE numBon = (SELECT estLieA FROM LigneBonEntrée WHERE numBon = numBonIn));
IF numLignesBonEntrée <> numLignesBonSortie THEN
SET test = FALSE;
ELSE
DECLARE cr1 CURSOR FOR SELECT codeArt, qte FROM LigneBonEntrée WHERE numBon = numBonIn ORDER BY codeArt ASC;
DECLARE cr2 CURSOR FOR SELECT codeArt, qte FROM LigneBonSortieWHERE numBon = (SELECT estLieA FROM LigneBonEntréeWHERE numBon = numBonIn) ORDER BY codeArt ASC;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET no_more_rows = TRUE;
OPEN cr1;
OPEN cr2;
the_loop: LOOP
FETCH cr1 INTO codeArtLigneBonEntrée, qteLigneBonEntrée;
FETCH cr2 INTO codeArtLigneBonSortie, qteLigneBonSortie;
IF no_more_rows THEN
CLOSE cr;
LEAVE the_loop;
END IF;
IF codeArtLigneBonEntrée <> codeArtLigneBonSortie THEN
SET test = FALSE;
END IF;
IF qteLigneBonEntrée <> qteLigneBonSortie THEN
SET test = FALSE;
END IF;
END LOOP the_loop;
END IF;
RETURN test;
END$$
DELIMITER ;