表类型(复合数据类型)
表类型
1表类型可以存储多行数据
语法
type tableName is table of dateType [not null] index by binary_integer ;
tableName:表类型名
is table:表示创建的是表类型
dateType:存储数据的类型
index by binary_integer :指定系统创建一个主键索引,用于引用表类型变量中的特定行
举例:
记录表类型存储方式
类似于数组
记录表类型的几种方法:
count:返回记录表的纪录的数量
delete:删除记录表的纪录
first:返回记录表最小索引值
last:返回记录表最大索引值
next:返回记录表下一个索引值,使用该方法前,需要传递一个索引值
案例
用for循环将表数据存入记录表中
declare
type stu is record(
age student.sage%type,
name student.sname%type
);
type array is table of stu index by binary_integer;
arr array;
m int:=1;
begin
for i in (select sage,sname from student) loop
arr(m):=i;
m:=m+1;
end loop;
for i in arr.first()..arr.last() loop
dbms_output.put_line(arr(i).age||’———-‘||arr(i).name);
end loop;
end;