1

plsqlでFORALLの後に1つの挿入ステートメントとコールプロシージャを作成するにはどうすればよいですか?

私は手順で以下を持っています

FORALL indx IN p_product.FIRST .. p_product.LAST
        INSERT INTO   my_table
              VALUES   (p_product(indx),p_product_desc(indx),p_msg);

挿入後、値を別のテーブルに挿入する別のプロシージャを呼び出したいと思います。

remove_dup_products(p_product(indx));

insert ステートメントの後に上記のプロシージャを呼び出そうとすると、エラーが発生します

INDX must be declared
4

1 に答える 1

2

FORALLステートメントはまさにそれです。声明; その中でできることは1つだけです。タイプをもう一度ループする必要があります。

forall indx in p_product.first .. p_product.last
   insert into my_table
   values (p_product(indx), p_product_desc(indx), p_msg);

for indx in p_product.first .. p_product.last loop
   remove_dup_products(p_product(indx));
end loop;

2 つの DML ステートメントを実行していないことには何の価値もありません。あなたはそれをやっていて、手続きを呼んでいます。したがって、FORALL を 2 回使用することはできません。通常の for ループを使用する必要があります。

2 番目の手順で DMLのみを実行している場合は、コレクション全体を渡してから FORALL を使用できます。グローバル変数を宣言する必要があります。

create or replace package something is

   type t__product is table of product.product%type;
   t_product t__product;

   ...

そして、これをどこでも再利用できます

create or replace package body something is

procedure current_proc is

begin

   forall indx in p_product.first .. p_product.last
      insert into my_table
      values (p_product(indx), p_product_desc(indx), p_msg);

   remove_dup_products(p_product);

end current_proc;

-------------------------------------------------------------

procedure remove_dup_products (p_product in t_product) is

begin

    forall in p_product.first .. p_product.last
       delete ...
于 2013-09-08T12:53:37.117 に答える