oracle存储过程

create or replace procedure update_hb_order_state is
--商城卡
CURSOR funds_ssk--前一天商城卡支付金额
IS
select t.order_id as order_id,is_reconciliation
from hb_order_settle t where t.settle_type = 2
and to_char(t.settle_time, 'yyyy-MM-dd') = to_char(sysdate - 1, 'yyyy-MM-dd');

CURSOR cusor_a--前一天商城卡支付金额根据订单号分组
IS
select t.order_id as order_id
from hb_order_settle t where t.settle_type = 2
and to_char(t.settle_time, 'yyyy-MM-dd') = to_char(sysdate - 1, 'yyyy-MM-dd') group by t.order_id;

--兑换卡
cursor funds_ddk--前一天兑换卡支付金额
is
select t3.id as order_id
from hb_goods_card t1, hb_goods_card_type t2, hb_order t3
where to_char(t1.change_time, 'yyyy-MM-dd') = to_char(sysdate - 1, 'yyyy-MM-dd')
and t1.type_code = t2.type_code and t3.goods_card_num = t1.card_num;

--实物销售
cursor funds_swss--前一天的实物销售数据
is
select t.id as order_id from hb_order t where t.order_type = 4
and to_char(t.insert_time, 'yyyy-MM-dd') = to_char(sysdate - 1, 'yyyy-MM-dd');

recon number;--1未对账

begin
    --如果商城卡支付全部已对账则将主订单对账状态改为0
    for a in cusor_a loop
        --判断是否全部已对账
        for b in funds_ssk loop
            if a.order_id = b.order_id
            then
                if b.is_reconciliation <> 0--如果这组订单包含未对账的
                then 
                     recon := 1;
                end if;
            end if;
        end loop;
        if recon <> 1
        then
            update hb_order t set t.is_reconciliation = 0 where t.id = a.order_id;
        end if;
    end loop;
  
    --兑换卡
    FOR o IN funds_ddk LOOP
        update hb_order t set t.is_reconciliation = 0 where t.id = o.order_id;
    end LOOP;
    
    --实物销售
    FOR o IN funds_swss LOOP
        update hb_order t set t.is_reconciliation = 0 where t.id = o.order_id;
    end LOOP;
    commit;
end update_hb_order_state;



 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值