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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/831188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:50:03  来源:igfitidea点击:

how to create a stored procedure in oracle which accepts array of parameters

oraclearraysstored-procedures

提问by RBS

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 中创建一个接受数组作为输入参数的存储过程以及如何创建?

回答by David

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;

回答by Lluis Martinez

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