0

実行するたびに異なる結果を返す選択クエリがある for ループがあるというシナリオがあります。すべての結果を単一の変数または配列またはカーソルに格納する必要があります。提案してください!!.以下は、パッケージに記述された手順です。

パッケージ仕様:

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;
4

1 に答える 1

0

配列を使用する代わりに、コレクション オブジェクトとして使用sys_refcursorして、複数の列を返すことができます。例えば

  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;
/
于 2013-08-22T10:13:57.747 に答える