call create_order_infos(2,3,300);
delimiter $$
create PROCEDURE `create_order_infos`(
In `in_user_id` int,
In `in_product_id` int,
In `in_count` INT)
BEGIN
# 定义总价格
declare all_price decimal(10,2);
declare product_price decimal(10,2);
declare count_money decimal(10,2);
# 需要计算购买产品所需的金额, 用户钱包是否足够支付
select price into product_price from product where product_id=in_product_id;
set all_price = product_price * in_count;
select balance into count_money from user_wallte where user_id=in_user_id;
if all_price>count_money then
signal sqlstate '45000' set message_text='金额不足,无法下单';
end if;
END $$
delimiter ;
添加一个用户下订单的存储过程,存储过程名称叫做【create_order_infos()】
最新推荐文章于 2024-06-29 14:10:39 发布