【发布时间】:2012-05-31 10:22:50
【问题描述】:
在 MySql 中
UPDATE `inventoryentry` SET `Status` = 1 WHERE `InventoryID`=92 AND `ItemID`=28;
它只成功更新了一行,其中 inventoryID = 92 和 itemID=28 ,显示以下消息。
1 row(s) affected
当我把它放在存储过程中时,如下
CREATE DEFINER=`root`@`localhost` PROCEDURE `Sample`(IN itemId INT, IN itemQnty
DOUBLE, IN invID INT)
BEGIN
DECLARE crntQnty DOUBLE;
DECLARE nwQnty DOUBLE;
SET crntQnty=(SELECT `QuantityOnHand` FROM `item` WHERE id=itemId);
SET nwQnty=itemQnty+crntQnty;
UPDATE `item` SET `QuantityOnHand`=nwQnty WHERE `Id`=itemId;
UPDATE `inventoryentry` SET `Status` = 1 WHERE `InventoryID`=invID AND
`ItemID`=itemId;
END$$
调用存储过程
CALL Sample(28,10,92)
它会根据 InventoryID(即 92)更新 inventoryentry 中的所有状态 = 1,忽略 ItemID,而不是只更新一行。显示以下消息!
5 row(s) affected
为什么存储过程在更新语句中忽略 itemID?或者为什么存储过程更新不止一次?但是没有存储过程它可以正常工作。
【问题讨论】:
-
检查服务器上是否执行了最新的sp脚本。
标签: mysql sql stored-procedures