pl/sql 表
在pl/sql块中临时使用、像数组一样的对象
包含一列和一个主键
不能对列和主键进行命名
列可以是任何标量数据类型
主键必须是binary_integer类型
大小没有限制
声明pl/sql表
定义表的类型
type 类型名 is table of 列类型|变量数据类型 index by binary_integer;
声明表变量
表名 类型名;
引用pl/sql表
表名(下标)
赋值
表名(下标):=表达式;
属性方法:
count --返回pl/sql表的总行数;
delect --删除pl/sql表的所有内容;
delect(行数) --删除pl/sql表的指定的行;
delct(开始行,结束行) --删除pl/sql表的多行;
first --返回表的第一个INDEX;
next(行数) --这个行数的下一条的INDEX;
last --返回表的最后一个INDEX;
declare
Type stuNameTableType is table of student.stu_name%type index by binary_integer;
stuNameTable stuNameTableType;
begin
for i in 1..10
loop
stunametable(i):='student'||i;
end loop;
for i in 1..stunametable.count
loop
dbms_output.put_line('第'||i||'个元素:'||stunametable(i));
end loop;
end;
表类型需要使用bulk collect批量绑定进行select赋值,bulk collect子句也可用于Fetch bulk collect into 子句中
declare
TYPE studentTableType is table of student%rowtype index by binary_integer;
studentTable studentTableType;
begin
select * bulk collect into studentTable from student order by stu_id;
for i in 1..studentTable.count loop
dbms_output.put_line(studentTable(i).stu_id);
dbms_output.put_line(studentTable(i).stu_name);
dbms_output.put_line(studentTable(i).stu_sex);
dbms_output.put_line(studentTable(i).stu_birthday);
end loop;
end;
Record类型
声明
type 记录类型名 is record (
字段1 类型[not null[:=表达式]]
字段n 类�