c 调用oracle函数,function 中调用自己?

这篇博客展示了如何使用PL/SQL进行递归查询,以解析BOM(物料清单)结构。通过声明变量和游标,从bom.bom_bill_of_materials, bom.bom_inventory_components和inv.mtl_system_items_b表中获取组件信息,并展示产品及其组件的详细信息,包括组件名称、描述、数量和子库存等。
摘要由CSDN通过智能技术生成

pl/sql 的递归,哈哈

declare

i       number;

j       number;

t1      bom.bom_inventory_components.item_num%type;

t2      bom.bom_inventory_components.component_quantity%type;

t3      bom.bom_inventory_components.supply_subinventory%type;

t4      inv.mtl_system_items_b.segment1%type;

t5      inv.mtl_system_items_b.description%type;

prod_item_id number;

prod_item_name inv.mtl_system_items_b.segment1%type;

prod_item_desc inv.mtl_system_items_b.description%type;

father_item_id number;

type arr is record (css   number);

TYPE type_tab IS TABLE OF arr INDEX BY BINARY_INTEGER;

t type_tab;

item type_tab;

cursor c is select bic.component_item_id,

bic.item_num,

bic.component_quantity,

bic.supply_subinventory,

msi.segment1,

msi.description

from bom.bom_bill_of_materials        bbom,

bom.bom_inventory_components     bic,

inv.mtl_system_items_b           msi

where bbom.organization_id = 32

and   bic.disable_date is null

and   bbom.bill_sequence_id = bic.bill_sequence_id

and   bic.component_item_id = msi.inventory_item_id

and   bbom.organization_id = msi.organization_id

and   bbom.assembly_item_id = father_item_id

order by bic.item_num;

begin

select a.inventory_item_id,  a.segment1,   a.description

into prod_item_id, prod_item_name, prod_item_desc

from inv.mtl_system_items_b a

where a.organization_id = 32

and a.segment1 = '&产品物料编码';

dbms_output.put_line('产品名称: '||prod_item_name||'    '||'产品说明: '||prod_item_desc);    --OUTPUT产品

dbms_output.put_line('');

dbms_output.put_line('    组件'||'                                '||'物料说明'||'                                '||'序号  '||'数量  '||'子库存');

father_item_id := prod_item_id;

dbms_output.put_line('----------------------------------------------------------------------------------------------------');

for i in 0..9 loop

t(i).css := 0;

item(i).css := 0;

end loop;

i := 1;

item(1).css := prod_item_id;

while t(0).css=0 loop

open c;

for j in 0..t(i).css loop

fetch c into father_item_id,t1,t2,t3,t4,t5;

if c%notfound then

father_item_id := 0;

else

item(i+1).css := father_item_id;

end if;

end loop;

if father_item_id=0 then

t(i).css := 0;

i := i -1;

t(i).css := t(i).css + 1;

father_item_id := item(i).css;

else

dbms_output.put_line(lpad(' ',i*2,' ')||'|-'||rpad(t4,40-(i*2+2),' ')||rpad(t5,40,' ')||rpad(t1,6,' ')||rpad(t2,6,' ')||t3);

i := i + 1;

end if;

close c;

end loop;

end;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值