Oracle集合类型(三)

2014-11-24 16:16:03 · 作者: · 浏览: 2
s_output.put_line(vnt_foregn_employees(v_row));
v_row := vnt_foregn_employees.next(v_row);
end loop;

end;

在稀疏集合中,经常需要使用NEXT方法遍历集合,提取数据。

6.2嵌套表示例

declare
type nt_employee is table of emp%rowtype;
vnt_employees nt_employee := nt_employee(); --构造函数显示初始化
c_big_number number := power(2, 31);
l_start_time pls_integer;

cursor cur_employee is
select * from emp;
vrt_employees cur_employee%rowtype;

begin
open cur_employee;
loop
fetch cur_employee
into vrt_employees;
exit when cur_employee%notfound;
vnt_employees.extend;
vnt_employees(vnt_employees.last) := vrt_employees;
end loop;
close cur_employee;

dbms_output.put_line(vnt_employees.count);

end;

6.3VARRAY实例

create or replace type nt_course is varray(5) of varchar2(100);
create table students( student_name varchar2(20) , cource nt_course);

declare
vnt_nt_courses nt_course := nt_course();
begin
vnt_nt_courses.extend(2);
vnt_nt_courses(1) := 'English';
vnt_nt_courses(2) := 'Chinese';

insert into students
(student_name, cource)
values
('chiclewu', vnt_nt_courses);

end;

可以使用TABLE函数把一个集合映射成数据库表.例如,要获取student表中课程列的记录。

select * from table (select s.cource from students s);