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;
/*****************************************************
* 修改商户批次状态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;
本文展示了如何在Oracle存储过程中使用嵌套游标来处理数据。通过一个名为`modify_customer_batch`的存储过程,演示了如何根据商户批次状态查询并更新相关记录。过程首先声明了一个游标`customer_batch_cursor`,用于获取处理中的商户批次,然后在循环中处理每个批次,检查其总记录数与付款批次处理的记录数是否匹配,如果匹配则更新商户批次状态为'SUCCESS'。
975

被折叠的 条评论
为什么被折叠?



