Get Updated Value in MySQL instead of affected rows

后端 未结 5 549
攒了一身酷
攒了一身酷 2020-11-30 04:59

I\'ve been trying to find an answer to this question, but haven\'t found any definitive \"yes\" or \"no\" in all my research.

I\'m running a simple MySQL query like

5条回答
  •  臣服心动
    2020-11-30 05:23

    If you don't want to run another Query SELECT then here is another way to do it. I have modified Mr. Berkowski code for reference:

    DELIMITER $$
    CREATE PROCEDURE increment_score
    (
       IN id_in INT
    )
    BEGIN
        set @newScore := null;
        UPDATE item SET score = IF((@newScore := score+1) <> NULL IS NULL, @newScore, NULL) WHERE id = id_in;
        SELECT @newScore;
    END
    DELIMITER ;
    

提交回复
热议问题