oracle光标位置无效,帮忙看下这段代码为什么总是报无效的游标,谢谢

declare

cursor c_cur1 is

select distinct c.segment1 as productno1

from BOM_BILL_OF_MATERIALS        a,   ---bom头表

BOM_INVENTORY_COMPONENTS     b,   ---bom明细

mtl_system_items_b           c,   ---物料表

mtl_system_items_b           d,

bom_operation_sequences      bos, ---工序明细(料品制程明细表)

bom_operational_routings     bor, ---工艺路线

BOM_DEPARTMENTs              bd,  ---部门代码对应表

org_organization_definitions ood

where a.BILL_SEQUENCE_ID = b.BILL_SEQUENCE_ID      ---清单序号(关键字)无实际含义,类似序列

and a.ORGANIZATION_ID = c.organization_id        ---组织代码

and a.ASSEMBLY_ITEM_ID = c.inventory_item_id     ---a.装配件内码 c 料品id

and a.ORGANIZATION_ID = d.organization_id

and b.COMPONENT_ITEM_ID = d.inventory_item_id    --- b 构件序号  d 料品id

and bos.routing_sequence_id = bor.common_routing_sequence_id

and bor.assembly_item_id = a.ASSEMBLY_ITEM_ID    ---bor 料品id

and bor.organization_id = a.ORGANIZATION_ID

and nvl(bor.alternate_routing_designator, 1) = nvl(a.ALTERNATE_BOM_DESIGNATOR, 1)

and bos.operation_seq_num = b.OPERATION_SEQ_NUM

and nvl(bos.disable_date, trunc(sysdate) + 1) >= sysdate

and nvl(operation_type, 1) = 1

and bos.department_id = bd.department_id

and a.ORGANIZATION_ID = ood.ORGANIZATION_ID

and c.segment1 like'5%'  ---半成品

and b.disable_date is null

and b.IMPLEMENTATION_DATE is not null

;

/**计算半成品成本**/

cursor c_cur3(v_productno1 IN mtl_system_items_b.segment1 %type) is

select a.segment1

,to_number(listagg(DECODE(a.costs_flag,'SB',a.costs),'') within group (order by DECODE(a.costs_flag,'SB',a.costs))) AS costs_sb

,to_number(listagg(DECODE(a.costs_flag,'RG',a.costs),'') within group (order by DECODE(a.costs_flag,'RG',a.costs))) AS costs_rg

from

(

SELECT msi.segment1

,case when br.resource_code like '%-SB' then 'SB' else 'RG' end as costs_flag

,sum(v.resource_rate*decode(bors.basis_type, 2, NULL, bors.usage_rate_or_amount))  as costs   -- 成本

FROM   bom_operational_routings     bor

,bom_operation_sequences      bos

,bom_operation_resources      bors

,bom_sub_operation_resources  bsor

,org_organization_definitions ood

,mtl_system_items_b           msi

,bom_resources                br

,bom_resources                br1

,bom_departments              bod

,cst_resource_costs_v v

WHERE  bor.routing_sequence_id = bos.routing_sequence_id

AND    bos.operation_sequence_id = bors.operation_sequence_id

AND    bors.operation_sequence_id = bsor.operation_sequence_id(+)

AND    bors.substitute_group_num = bsor.substitute_group_num(+)

AND    bor.organization_id = ood.organization_id

AND    bor.assembly_item_id = msi.inventory_item_id

AND    bor.organization_id = msi.organization_id

AND    bors.resource_id = br.resource_id

AND    bsor.resource_id = br1.resource_id(+)

AND    bos.department_id = bod.department_id

AND    V.resource_id = BORS.RESOURCE_ID

AND    nvl(bos.effectivity_date, SYSDATE - 1) < SYSDATE

AND    nvl(bos.disable_date, SYSDATE + 1) > SYSDATE

AND    bor.organization_id = 84

AND    msi.segment1 = v_productno1

GROUP BY msi.segment1,case when br.resource_code like '%-SB' then 'SB' else 'RG' end

) a

group by a.segment1

;

row_semi_product c_cur3%rowtype;

BEGIN

/**将半成品的成本数据插入新建的临时表semi_product_costs**/

FOR r_cur1 IN c_cur1 LOOP

FOR r_cur3 IN c_cur3(r_cur1.productno1) loop

fetch c_cur3 into row_semi_product;

exit when c_cur3%notfound;

Insert Into semi_product_costs values row_semi_product;

DBMS_OUTPUT.ENABLE(1000000);

DBMS_OUTPUT.PUT_LINE(r_cur3.segment1||' '||r_cur3.costs_rg||' '||r_cur3.costs_sb);

END LOOP;

commit;

END LOOP;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值