如何在oracle中创建一个接受参数数组的存储过程

时间:2022-06-01 16:02:43

Can any one tell me if its possible to create a stored procedure in oracle which accept array as an input parameter and how ?

任何人都可以告诉我是否有可能在oracle中创建一个存储过程接受数组作为输入参数以及如何?

2 个解决方案

#1


13  

Yes. Oracle calls them collections and there's a variety of collections you can use.

是。 Oracle将它们称为集合,并且您可以使用各种集合。

A simple array example using a VARRAY.

使用VARRAY的简单数组示例。


DECLARE
  TYPE Str_Array IS VARRAY(4) OF VARCHAR2(50);
  v_array  Str_Array;

  PROCEDURE PROCESS_ARRAY(v_str_array  Str_Array)
  AS
  BEGIN
    FOR i IN v_str_array.first .. v_str_array.last LOOP
      DBMS_OUTPUT.PUT_LINE('Hello '||v_str_array(i));
    END LOOP;
  END;

BEGIN

  v_array := Str_Array('John','Paul','Ringo','George');

  PROCESS_ARRAY(v_array);

  -- can also pass unbound Str_Array
  PROCESS_ARRAY(Str_Array('John','Paul','Ringo','George'));

END;

#2


1  

If I'm not wrong, there's a native type called TABLE that basically is an array. But last time I used it was 2001 so maybe there are most powerful types nowadays.

如果我没错,那就是一个名为TABLE的本机类型,它基本上就是一个数组。但是上次我用它是2001年所以也许现在有最强大的类型。

Check this http://www.developer.com/db/article.php/3379271

请查看http://www.developer.com/db/article.php/3379271

#1


13  

Yes. Oracle calls them collections and there's a variety of collections you can use.

是。 Oracle将它们称为集合,并且您可以使用各种集合。

A simple array example using a VARRAY.

使用VARRAY的简单数组示例。


DECLARE
  TYPE Str_Array IS VARRAY(4) OF VARCHAR2(50);
  v_array  Str_Array;

  PROCEDURE PROCESS_ARRAY(v_str_array  Str_Array)
  AS
  BEGIN
    FOR i IN v_str_array.first .. v_str_array.last LOOP
      DBMS_OUTPUT.PUT_LINE('Hello '||v_str_array(i));
    END LOOP;
  END;

BEGIN

  v_array := Str_Array('John','Paul','Ringo','George');

  PROCESS_ARRAY(v_array);

  -- can also pass unbound Str_Array
  PROCESS_ARRAY(Str_Array('John','Paul','Ringo','George'));

END;

#2


1  

If I'm not wrong, there's a native type called TABLE that basically is an array. But last time I used it was 2001 so maybe there are most powerful types nowadays.

如果我没错,那就是一个名为TABLE的本机类型,它基本上就是一个数组。但是上次我用它是2001年所以也许现在有最强大的类型。

Check this http://www.developer.com/db/article.php/3379271

请查看http://www.developer.com/db/article.php/3379271