我用mysql写了一个程序,错误信息是mysql procedure subquery返回1行以上,不知道有没有人能帮我
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
PROCEDURE `vente`(IN `Lieu` VARCHAR(5),
IN `Objet` INT, IN `Quantite` INT(3),
IN `jour` INT(3), IN `Id_Mois` INT(3),
IN `Annee` INT(3), IN `artisan` INT(3),
IN `artisan2` VARCHAR(5), IN `deco` VARCHAR(5),
IN `deco2` VARCHAR(5), IN `pouvoir` VARCHAR(5),
IN `Oo` VARCHAR(5), IN `Oa` VARCHAR(5),
IN `of` VARCHAR(5))
BEGIN
SET @Numventee = (SELECT ID_vente FROM commande ORDER BY ID_vente DESC LIMIT 1 ) ;
SET @Numvente = @Numventee +1 ;
INSERT INTO commande (ID_Lieu,ID_Objet,Quantite_objet,Jour,id_Mois,Annee, id_pouvoir)
SELECT Lieu,Objet,Quantite,Jour,Id_Mois,Annee, pouvoir
LIMIT 1;
INSERT INTO realiser (ID_Vente,ID_Artisan)
SELECT @Numvente,Artisan
ORDER BY ID_vente LIMIT 1;
INSERT INTO realiser (ID_vente,ID_artisan)
SELECT @Numvente,artisan2
Where artisan2 <> 'NULL' LIMIT 1;
INSERT INTO composer (ID_Vente,ID_Deco)
SELECT @Numvente,Deco
Where Deco <> 'NULL' LIMIT 1;
INSERT INTO composer (ID_vente,ID_deco)
SELECT @Numvente,Deco2
Where Deco2 <> 'NULL' LIMIT 1;
INSERT INTO couter (ID_Vente,ID_Monnaie,Quantite_Monnaie)
SELECT @Numvente,1,Oo
Where Oo <> 'NULL' LIMIT 1;
INSERT INTO couter (ID_vente,ID_Monnaie,Quantite_Monnaie)
SELECT @Numvente,2,Oa
Where Oa <> 'NULL' LIMIT 1;
INSERT INTO couter (ID_vente,ID_Monnaie,Quantite_Monnaie)
SELECT @Numvente,3,Of
Where Of <> 'NULL' LIMIT 1;
END$$
DELIMITER ;
抱歉,我不知道怎么把代码写在blocnote上
1条答案
按热度按时间hgqdbh6s1#
你应该使用
LAST_INSERT_ID()
获取行的新自动增量id。而不是使用所有这些SELECT
语句来条件化插入,使用IF
声明。