c mysql 单个值_Mysql 存储过程返回单个值和多个值

1:返回单个值

-- 返回单个值

CREATE PROCEDURE fetch_ufmall_code_seq(IN inseqName varchar(50),OUT outseqcode int)

BEGIN

select seq_code into outseqcode from m_ufmall_seq_produce where seq_name = inseqName;

update m_ufmall_seq_produce set seq_code = seq_code + 1 where seq_name = inseqName;

select outseqcode;

END;

-- 调用

call fetch_ufmall_code_seq('produce_order_payment_seq',@a);

b652e975406220eba886098ceebe2885.png

2:返回多个值

-- 返回多个值

CREATE PROCEDURE proc_stat_ufmall_verify(OUT total_order_num int,OUT total_refund_num int,OUT total_cost_money decimal,OUT total_in_money decimal)

BEGIN

-- 商城商品已售单数

select count(0) into total_order_num from m_ufmall_order_payment where not EXISTS

(select id from m_ufmall_order_refund where refund_money is not null and m_ufmall_order_payment.order_code = m_ufmall_order_refund.order_code);

-- 商城商品已退款单数

select count(0) into total_refund_num from m_ufmall_order_refund where refund_money is not null;

-- 商城商品成本费用合计

select sum(product_cost_price) into total_cost_money from m_ufmall_product  mup INNER JOIN m_ufmall_order muo ON mup.id = muo.product_id

and EXISTS(

select m_ufmall_order_payment.order_code from m_ufmall_order_payment where not EXISTS

(select id from m_ufmall_order_refund where refund_money is not null and m_ufmall_order_payment.order_code = m_ufmall_order_refund.order_code)

and muo.order_code = m_ufmall_order_payment.order_code

);

-- 商城商品收入

select sum(actual_order_money) into total_in_money from m_ufmall_order_payment where not EXISTS

(select id from m_ufmall_order_refund where refund_money is not null and m_ufmall_order_payment.order_code = m_ufmall_order_refund.order_code);

select total_order_num,total_refund_num,total_cost_money,total_in_money;

END;

-- 调用

call proc_stat_ufmall_verify(@a,@b,@c,@d);

1553f7d307fcf030770ae3f31afb788b.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值