在PL/SQL中是没有数组(Array)概念的。但是如果程序员想用Array的话,就得变通一下,用TYPE和Table of Record来代替多维数组.
分类:可变数组和固定数组
1.固定数组
declare
type v_ar is varray(10) of varchar2(30);--数组的类型varchar2,长度为10
my_ar v_ar:=v_ar('22','33','2','4','8');
begin
for i in 1..my_ar.count
loop
dbms_output.put_line(my_ar(i));
end loop;
end;
如果定义成某个变的某列的类型一样,表名.字段名称(table.clum%type)
type array_t is varray(10) of school.school_name%type;
2.可变数组
declare
type v_table is table of varchar2(30) index by binary_integer;
--没有定义数组的长度,index by定义数组的下标是整数.
my_table v_table;
begin
for i in 1..20
loop
my_table(i):=i;
dbms_output.put_line(my_table(i));
end loop;
end;
用嵌套表的数组
type stdInfo is record(stdId varchar(30),comment varchar(1));
type myArray is table of stdInfo index by binary_integer;