mysql简单的存储过程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liu1765686161/article/details/80647455
#Drop PROCEDURE proc_data;
DELIMITER //
CREATE  PROCEDURE proc_data(IN userId varchar(50),in amount bigint,in levels int)

BEGIN
DECLARE counts INT DEFAULT 0;
DECLARE valueP bigint DEFAULT 0;
DECLARE lockValueP bigint DEFAULT 0;
DECLARE doubleAmount bigint; #网点代码
DECLARE descHis varchar(255); #网点代码

INSERT INTO `lock_coin` (`user_id`, `coin_type`, `amount`, `create_tm`, `level`, `income`) VALUES (userId, 'STC', amount, sysdate(), levels, amount * 5);
select value,lock_value  into valueP ,lockValueP from user_coin where user_id = userId and `level` = levels and coin_type = 'STC';
#select count(0) into counts from user_coin where user_id = userId and `level` = levels
#if counts > 0 then
update user_coin set value = value - amount , lock_value = lock_value + amount ,
`version` = `version` + 1 where user_id = userId and `level` = levels ;
#else
#end if;
set doubleAmount = amount/100000000;
set descHis = CONCAT('第',levels,'阶段STC变动量',doubleAmount,',余额减少',doubleAmount,',锁定量增加',doubleAmount);
INSERT INTO `user_coin_his` (`user_id`, `coin_type`, `amount`, `balance`, `lock_balance`, `op_info`, `trade_type`, `create_tm`) VALUES ( userId, 'STC', amount, valueP-amount,
amount+lockValueP, descHis, 5,sysdate());


END ;
//
DELIMITER ;

call proc_data(2,10000000000,1);

希望能帮到大家,欢迎大家一起分享。

觉得有用请打赏,你的鼓励就是我的动力!

         

有问题可以通过chat向我提问,共同进步


猜你喜欢

转载自blog.csdn.net/liu1765686161/article/details/80647455
今日推荐