declare
/*嵌套表*/
type a_t is table of varchar2(50);
a a_t;
/*索引表*/
type b_t is table of varchar2(50) index by pls_integer;
b b_t;
row_index pls_integer;
/*输出a的第一个元素值*/
function a_f(p_a in a_t) return varchar2 is
begin
return p_a(p_a.first);
end;
/*对b进行更新,返回b_t类型*/
function b_f(p_b in b_t) return b_t is
b b_t;
begin
b := p_b;
b(p_b.last + 1) := 'd';
return b;
end;
begin
/*嵌套表*/
a := new a_t(); --初始化
a.extend(3); --使用extend方法进行扩展
a(1) := 'a';
a(2) := 'b';
a(3) := 'c';
for i in a.first .. a.count --count方法获取a的个数
loop
dbms_output.put_line(a(i));
end loop;
/*调用function a*/
dbms_output.put_line('call function a...');
dbms_output.put_line(a_f(a));
dbms_output.put_line('--------------------------');
/*索引表(关联数组),无需初始化*/
b(-1) := 'a';
b(2) := 'b';
b(23) := 'c';
for i in b.first .. b.last --fisrt和last来确定边界
loop
if b.exists(i) --看是否有值
then
dbms_output.put_line(b(i));
end if;
end loop;
/*调用function b*/
dbms_output.put_line('call function b...');
b := b_f(b);
row_index := b.first;
loop
exit when row_index is null;
if b.exists(row_index) --看是否有值
then
dbms_output.put_line(b(row_index));
end if;
row_index := b.next(row_index);--方法next返回下个索引
end loop;
end;
PLSQL总结——13.集合
最新推荐文章于 2023-09-08 21:15:00 发布