3,487
社区成员




第一步全部放入my_table表:insert into my_table values(t_bill_detail_nc)?
第二步遍历 t_bill_detail_nc 表对象数据,取出bill_detail_id去更新t_wh_bill_detail表中字段的状态。
create or replace type o_bill_detail as object
(
bill_detail_id number, --业务单据明细ID
trans_type_id number, -- 业务单据类型ID
trans_type_code varchar2(20), -- 业务单据类型编码
trans_type_name varchar2(50), -- 业务单据类型名称
item_id number, -- 物料ID
warehouse_id number, -- 仓库ID
nc_batch_code varchar2(50), -- 批次
nc_dispatcher_id varchar2(50), -- NC单据编码
supplier_id number, -- 供应商ID
nc_norgnet_tax_price float, -- NC价格
nc_number number, -- 数量
nc_inventory_code varchar2(100), -- NC存货编码
nc_warehouse_id varchar2(50), -- NC仓库编码
nc_whether_batch varchar2(2), -- NC是否批次管理
nc_supplier varchar2(50), -- NC供应商编码
mes_uuid varchar2(50), -- MES唯一码
mes_date varchar2(25) -- MES同步日期
)
--自定义table对象
create or replace type t_bill_detail_nc is table of o_bill_detail
--测试脚本
function bills_cgrk_syn_list(p_req_purchaser in varchar2) return t_bill_detail_nc is
bill_detail_nc_tab t_bill_detail_nc; --自定义表对象类型
bill_detail_nc_o o_bill_detail; --自定义表对象类型
begin
--select t_bill_detail_nc(rs.*) into bill_detail_nc_tab from (
select t_bill_detail_nc (
tb.bill_detail_id,
tb.trans_type_id,
tb.trans_type_code,
tb.trans_type_name,
tb.item_id,
tb.warehouse_id,
tb.nc_batch_code,
tb.nc_dispatcher_id,
tb.supplier_id,
tb.nc_norgnet_tax_price,
tb.nc_number,
t3.nc_item_code,
t5.interface_code,
decode(nvl(t4.islot, '0'), '1', 'Y', 'N') ,
t6.interface_code,
sys_guid(),
to_char(sysdate,'yyyy-mm-dd HH24:mi:ss'))
into bill_detail_nc_tab
from (select t2.bill_detail_id,
t1.trans_type_id,
t1.trans_type_code,
t1.trans_type_name,
t2.item_id,
t2.wh_id as warehouse_id,
t2.lot as nc_batch_code,
t1.interface_code as nc_dispatcher_id,
t.supplier_id,
td.price as nc_norgnet_tax_price,
t2.act_receive_qty as nc_number
from t_wh_bill t
left join t_wh_trans_bill_type t1
on t.trans_type_id = t1.trans_type_id
left join t_wh_bill_detail t2
on t2.bill_id = t.bill_id
left join t_po_order_detail td
on t2.po_order_detail_id = td.order_detail_id
where t2.bill_status = '1'
and nvl(t2.nc_status, 0) = '0'
and t2.mes_sid is null
and t.bill_date >= '2018-03-01'
and t.bill_date <= '2018-03-07'
and instr(t1.trans_type_code, C_CGRK_CODE) > 0) tb
left join t_basic_item t3
on tb.item_id = t3.item_id
left join t_basic_item_logistics t4
on tb.item_id = t4.item_id
left join t_wh_info t5
on tb.warehouse_id = t5.wh_id
left join t_basic_supplier t6
on t6.supplier_id = tb.supplier_id;
return bill_detail_nc_tab;
end bills_cgrk_syn_list;
-- 给你写个例子
SQL>
SQL> create type t_type as object(
2 id int,
3 name varchar(10),
4 remark varchar(10)
5 );
6 /
Type created
SQL> create type tt_type is table of t_type;
2 /
Type created
SQL> create or replace function fn(p varchar2) return tt_type is
2 v_tt_type tt_type;
3 begin
4 select t_type(100, p, 'remark')
5 bulk collect
6 into v_tt_type
7 from user_objects
8 where rownum <= 5;
9 return v_tt_type;
10 end;
11 /
Function created
SQL> set serverout on;
SQL> declare
2 result tt_type;
3 begin
4 result := fn('dddddd');
5 dbms_output.put_line('count = ' || result.count);
6 end;
7 /
count = 5
PL/SQL procedure successfully completed
SQL> drop type tt_type;
Type dropped
SQL> drop type t_type;
Type dropped
SQL> drop function fn;
Function dropped
SQL>