oracle pl/sql 数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3545379/
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 02:44:56  来源:igfitidea点击:

oracle pl/sql arrays

arraysoracleplsql

提问by Andromeda

i have some numbers which i want to store in an array. how will i declare array and assign value to it in oracle pl/sql??

我有一些我想存储在数组中的数字。我将如何在 oracle pl/sql 中声明数组并为其赋值?

回答by Damian Leszczyński - Vash

There are array type in PL/SQL but we can create those ourselves using the table

PL/SQL 中有数组类型,但我们可以使用表自己创建它们

declare 
  type NumberArray is table of number index by binary_integer;
  myArray NumberArray;
begin

   myArray(0) := 1
   myArray(1) := 2 
   --or use a for loop to fill
end;

The explanation article

说明文章

EDIT:

编辑

or as Adam Muschsaid if we know the data size of data, that we are operating on, we can use VARRAYsthat are length fixed, this is oracleenvironment, so subscripts start from 1,

或者正如Adam Musch所说,如果我们知道我们正在操作的数据的数据大小,我们可以使用VARRAYs长度固定的,这是oracle环境,所以下标从1

Alternative is using VARRAY, where array subscript starts from 1 and the length of VARRAYs is fixed.

另一种方法是使用VARRAY,其中数组下标从 1 开始,并且 VARRAY 的长度是固定的。

Semantic:

语义:

declare  type VarrayType is varray(size) of ElementType;

Example :

例子 :

    declare
      type NumberVarray is varray(100) of NUMERIC(10);
      myArray NumberVarray;
    BEGIN
      myArray := NumberVarray(1,10,100,1000,10000);

      myArray(1) = 2;

      for i in myArray.first..myArray.last
      loop
        dbms_output.put_line('myArray(' || i || '): ' || myArray(i));
      end loop;  
    end;
END;

Output :

输出 :

myArray(1) : 2
myArray(2) : 10
myArray(3) : 100
myArray(4) : 1000
myArray(5) : 10000