我的mysql数据库中有以下存储过程:
BEGIN
DECLARE useCount, remainingUses INT DEFAULT 0;
/* Get the current values for the quiz into the variables */
SELECT remaining_uses, use_count INTO remainingUses, useCount FROM quiz_passwords WHERE password_id = passwordId;
/* Are there remaining uses to consume? */
if (remainingUses > 0) THEN
UPDATE quiz_passwords SET use_count = (useCount + 1), remaining_uses = (remainingUses - 1) where password_id = passwordId;
END IF;
END如您所见,只有当初始remainingUses语句中的select变量大于'0‘时,才应该执行update语句。
但是,当我调用过程CALL UsePassword(197);时,它返回Affected rows: 1。
我不明白,当数据库中的id = 197密码行的值为'remaining_uses = 0‘时。
如果要在结果中显示Affected rows: 1,有什么原因吗?
如果语句被成功执行,它会返回一个受影响的行吗?因为在本例中,技术上没有执行UPDATE语句。
更新不仅没有更新,而且如果我完全删除update语句,它仍然告诉我有一个受影响的行!
谢谢
发布于 2013-03-30 08:20:44
最后,通过在存储过程中声明OUT变量,然后在SELECT语句之后设置它的值来返回值,从而解决了这个问题。
/* Return the affected rows */
SET affected_rows = ROW_COUNT();https://stackoverflow.com/questions/15708020
复制相似问题