jane邦德

导航

处理存储过程获取的集合数据

在一个存储过程里面调用另一个存储过程,处理获取到的集合数据进行处理,因为简单的for loop用不了,所以研究出以下方法:

--包头
CREATE OR REPLACE PACKAGE mms_pms_material_stock_pkg IS
TYPE record_set IS REF CURSOR;
--1,定义一个类型stock_rec
TYPE stock_rec IS RECORD(
ITEM_BARCODE VARCHAR2(100),
CASE_BARCODE VARCHAR2(100),
MATERIAL_STOCK_DETAIL_ID NUMBER,
MATERIAL_STOCK_ID NUMBER,
SERIAL_NUMBER_CONTROL_CODE NUMBER
);
--执行报表相关存储过程,然后保存到中间表mms_pms_material_stock_daily。
PROCEDURE gen_stock_data_daily
(
p_record_count OUT NUMBER,
p_retcode OUT VARCHAR2,
p_errmsg OUT VARCHAR2
);
END mms_pms_material_stock_pkg;

--包体
CREATE OR REPLACE PACKAGE BODY mms_pms_material_stock_pkg IS
PROCEDURE gen_stock_data_daily
(
p_record_count OUT NUMBER,
p_retcode OUT VARCHAR2,
p_errmsg OUT VARCHAR2
) AS
--2,将record_set返回集合定义SYS_REFCURSOR
p_material_stock_detail_list SYS_REFCURSOR;
--3,定义一个stock_rec类型的temp后用
stock_temp stock_rec;
BEGIN
mms_material_stocks_pkg.query_material_stock_details(
p_user_id => 2,
p_role_id => 10,
p_erp_organization_id => 1513,
p_begin_rownum => 0,
p_end_rownum => p_record_count+1,
p_record_count => p_record_count,
p_material_stock_detail_list => p_material_stock_detail_list);
end if;
if p_record_count > 0 then
p_retcode := 'S';
--4,开始遍历,fetch到temp
fetch p_material_stock_detail_list into stock_temp;
while p_material_stock_detail_list%found loop
dbms_output.put_line('字段1:'||stock_temp.ITEM_BARCODE );
fetch p_material_stock_detail_list into stock_temp;
end loop;
end if;
p_retcode := 'S';
EXCEPTION
WHEN OTHERS THEN
p_retcode := 'F';
p_errmsg := substr(SQLERRM, 12, 2000);
END;
END mms_pms_material_stock_pkg;

PS:参考了以下两位的经验:https://www.cnblogs.com/shenyuelan/p/3360049.html(深月蓝),https://www.cnblogs.com/javacofe/p/8203947.html(洋流季)

posted on 2020-09-22 17:36  jane邦德  阅读(383)  评论(0编辑  收藏  举报