oracle中存储 过程嵌套游标的使用

本文展示了如何在Oracle存储过程中使用嵌套游标来处理数据。通过一个名为`modify_customer_batch`的存储过程,演示了如何根据商户批次状态查询并更新相关记录。过程首先声明了一个游标`customer_batch_cursor`,用于获取处理中的商户批次,然后在循环中处理每个批次,检查其总记录数与付款批次处理的记录数是否匹配,如果匹配则更新商户批次状态为'SUCCESS'。
摘要由CSDN通过智能技术生成
create or replace procedure modify_customer_batch as
/*****************************************************
  * 修改商户批次状态customserBatch
  * authorization: xianyin.li
  * last modify time: 2016-12-26
  ******************************************************/
  v_remit_bill_total_count customer_batch.total_count%type;--付款批次总记录数
  v_customer_batch_count   customer_batch.total_count%type;--商户批次总笔数
  v_customer_batch_id      customer_batch.id%type;         --商户id
  --声明游标
  cursor customer_batch_cursor is
    select ctb.id, ctb.total_count
      from customer_batch ctb
     where ctb.status = 'PROCESSING';
begin
  open customer_batch_cursor;
  loop
    --循环游标
    fetch customer_batch_cursor
      into v_customer_batch_id, v_customer_batch_count;
    exit when customer_batch_cursor%notfound;
    begin
      --查询商户批次总笔数是否存在
      if v_customer_batch_count = 0 then
        goto point_1;
      end if;
    
      --查询付款批次处理的总记录数
      select count(*)
        into v_remit_bill_total_count
        from remit_bill rb
       where rb.customer_batch_id = v_customer_batch_id
         and rb.batch_status = 'PROCESSING';
    
      if v_remit_bill_total_count = v_customer_batch_count then
        --修改商户批次状态
        update customer_batch ctb
           set ctb.status = 'SUCCESS'
         where ctb.id = v_customer_batch_id
           and ctb.status = 'PROCESSING';
      end if;
      <<point_1>>
    
      commit;
    end;
  end loop;
  close customer_batch_cursor;


end;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值