处理复合变量的游标操作

本文介绍了一个使用PL/SQL实现的批量数据处理示例。通过定义游标及记录类型,该示例展示了如何从两个不同的表中批量获取并处理数据。首先,它从第一个表中获取一批记录,并针对每条记录打开第二个游标来获取相关联的数据集,然后进行后续处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

declare
  cursor get_xmm01_cur(in_batch_id number, in_org_id number) is
    select xmm_01.*
      from MG_MFG_39_GT_01_LD xmm_01
     where xmm_01.batch_id = in_batch_id
       and xmm_01.org_id = in_org_id
       and xmm_01.process_code is null
       for update nowait;

  cursor get_xmm02_cur(in_header_ridx number) is
    select xmm_02.*
      from MG_MFG_39_GT_02_LD xmm_02
     where xmm_02.header_ridx = in_header_ridx
       for update nowait;

  Type xmm02_tbl Is Table Of MG_MFG_39_GT_02_LD%rowtype Index By Binary_Integer;

  type xmm_rtype is record(
    xmm01_rtype get_xmm01_cur%rowtype,
    xmm02_rtype xmm02_tbl);

  Type xmm_rec Is Table Of xmm_rtype Index By Binary_Integer;
  ln_cnt     number := 1;
  in_bom_tbl xmm_rec;
  n          number;
begin
  open get_xmm01_cur(1, 207);
  loop
    fetch get_xmm01_cur
      into in_bom_tbl(ln_cnt).xmm01_rtype;
      dbms_output.put_line(': ' ||get_xmm01_cur%rowcount);
    exit when get_xmm01_cur%NOTFOUND;
  
    open get_xmm02_cur(in_bom_tbl(ln_cnt).xmm01_rtype.header_ridx);
    fetch get_xmm02_cur bulk collect
      into in_bom_tbl(ln_cnt).xmm02_rtype;
      dbms_output.put_line('2--' ||in_bom_tbl(ln_cnt).xmm02_rtype.count);
    close get_xmm02_cur;
  
    if in_bom_tbl(ln_cnt).xmm02_rtype.count = 0 then
      dbms_output.put_line(': ' ||
                           'there is no record to be processed in line!');
    end if;
    ln_cnt := ln_cnt + 1;
  end loop;
  if get_xmm01_cur%rowcount = 0 then
    dbms_output.put_line(': ' ||
                         'there is no record to be processed in head!');
  end if;
  close get_xmm01_cur;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值