存储过程需要的问题

1. 存储过程declare的变量不要和数据库字段名一样 啊,不然可能插入时是Null

DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `fAddScore`(IN `_userid` int,IN `_gold` bigint,IN `_typeInfo` varchar(50),IN `_des` VARCHAR(50),IN `_roomId` int,IN `_roomName` varchar(50),`_drawId` varchar(50))
BEGIN
    declare _gameId varchar(25);
    declare _scoreType tinyint(4);
    declare oldGold bigint;
    declare newGold bigint;
select gameID,cashGold into gameId,oldGold from User a,UserAccount b where a.id=b.userId and b.userId = _userid;
select scoreType into scoreType from ScoreTypeInfo where typeInfo = _typeInfo;
set newGold = oldGold + _gold;
    if newGold < 0 then
          set newGold = 0;
end if;
update UserAccount set cashGold = newGold where userId = _userid;
insert into ScoreLog(userId,gameID,oldScore,scoreChange,scoreType,typeInfo,source,drawId,collectDate,roomId,roomName) values(_userid,gameId,oldGold,_gold,scoreType,_typeInfo,_des,_drawId,now(),_roomId,_roomName);
END ;;

 

posted @ 2021-11-29 18:38  zjhgx  阅读(43)  评论(0编辑  收藏  举报