56,679
社区成员
发帖
与我相关
我的任务
分享
delimiter //
CREATE PROCEDURE global_shops(
in_item_id int(10),
in_max_count int(10),
in_count int(10),
OUT out_can_buy tinyint(2)
)
BEGIN
declare currcount int(10);
declare can_buy tinyint(2);
START TRANSACTION;
update g_shop set count = count + in_count where item_id = in_item_id;
select count into currcount from g_shop where item_id = in_item_id;
if( currcount <= in_max_count) then
set out_can_buy = 1;
COMMIT;
else
set out_can_buy = 0;
ROLLBACK;
end if;
END
//
DELIMITER ;