我有一个场景,一个有for循环的过程,其中有一个select查询,每次运行时返回不同的结果。我必须将每个结果存储在单个变量或数组或光标中。请提示!!。下面提供的是程序包中写的程序:
包装规格:
TYPE t_product_id IS TABLE OF products.productnr%TYPE
INDEX BY PLS_INTEGER;
TYPE t_product_desc IS TABLE OF varchar(100)
INDEX BY PLS_INTEGER;
Type t_product_psnr IS TABLE OF prodsubs.PSNR%TYPE
INDEX BY PLS_INTEGER;
TYPE t_prod_contractperiod IS TABLE OF prodrul.CONTRPEROFPSNR%TYPE
INDEX BY PLS_INTEGER;
Type t_output IS TABLE OF prodrul.ALLOWEDCUSTTYPES%TYPE
INDEX BY PLS_INTEGER;
包体:
PROCEDURE x_proc_Validprodcusttypeacctyp (
i_prodnr IN t_product_id,
i_invoiceprd IN prodrul.ALLOWEDINVPERIOD%TYPE,
i_psnr IN t_product_psnr,
i_contactprd IN t_prod_contractperiod,
i_result OUT t_output
)
IS
BEGIN
FOR i IN i_prodnr.FIRST .. i_prodnr.LAST
`LOOP
BEGIN
select PRODUCTNR,PRODUCTUSERKEY,ALLOWEDCUSTTYPES,ALLOWEDACCNTTYPES
into i_result (i)`
from prodrul rul join products prods on rul.PRODUCTNROFPSNR = prods.productnr
where prods.productnr = i_prodnr (i) and ALLOWEDINVPERIOD= i_invoiceprd and CONTRPEROFPSNR= i_contactprd (i)
and prods.productnr not in(select productnr from products where SMARTCARDYN = 1)
and rul.PRODUCTNROFPSNR not in (select PSPRODUCTNR from prodsubs join decoders on prodsubs.PSNR = decoders.DECSCPSNR where prodsubs.PSNR= i_psnr (i));
END;
END LOOP;
END x_proc_Validprodcusttypeacctyp;
答案 0 :(得分:0)
您可以使用sys_refcursor
作为集合对象来返回多个列而不是使用数组。
E.g。
CREATE OR REPLACE PROCEDURE x_proc_validprodcusttypeacctyp (
i_prodnr IN t_product_id,
i_invoiceprd IN prodrul.allowedinvperiod%TYPE,
i_psnr IN t_product_psnr,
i_contactprd IN t_prod_contractperiod,
i_result OUT t_output,
o_cursor OUT SYS_REFCURSOR
)
IS
BEGIN
OPEN o_cursor FOR
SELECT productnr, productuserkey, allowedcusttypes, allowedaccnttypes
FROM prodrul rul
JOIN
products prods
ON rul.productnrofpsnr = prods.productnr
WHERE prods.productnr = i_prodnr
AND allowedinvperiod = i_invoiceprd
AND contrperofpsnr = i_contactprd
AND prods.productnr NOT IN (SELECT productnr
FROM products
WHERE smartcardyn = 1)
AND rul.productnrofpsnr NOT IN
(SELECT psproductnr
FROM prodsubs
JOIN
decoders
ON prodsubs.psnr =
decoders.decscpsnr
WHERE prodsubs.psnr = i_psnr);
END;
/