oracle中数组的运用

--- define 一维数组

DECLARE
TYPE T_VARRAY IS VARRAY(5) OF NUMBER;
V_VAR T_VARRAY := T_VARRAY(1, 2, 3, 4, 5);
BEGIN
FOR I IN 1 .. V_VAR.COUNT LOOP
DBMS_OUTPUT.PUT_LINE(V_VAR(I));
END LOOP;
END;

---define 二维数组

declare
type structlist is table of varchar2(20);
type struct_structlist is table of structlist;
sl struct_structlist;
begin
sl := struct_structlist(structlist('10a', 20, 30, 40, 50),
structlist(10, '20a', 30, 40, 50),
structlist(1, 2, '3a', 4, 5));
for i in sl.first .. sl.last loop
for j in sl(i).first .. sl(i).last loop

dbms_output.put_line(sl.count||' @ '||sl(i).count||' - '||sl(i) (j));
end loop;
end loop;
end;

DECLARE
TYPE T_VARRAY IS VARRAY(5) OF varchar2(10);
TYPE T_VARRAY_VARRAY IS VARRAY(4) OF T_VARRAY;
V_VAR T_VARRAY_VARRAY := T_VARRAY_VARRAY(T_VARRAY('10a', 20, 30, 40, 50),
T_VARRAY(10, '20a', 30, 40, 50),
T_VARRAY(1, 2, '3a', 4, 5),
T_VARRAY(1, 2, 3, 4, 5));
begin
FOR I IN 1 .. V_VAR.COUNT LOOP
FOR J IN 1 .. V_VAR(I).COUNT LOOP
DBMS_OUTPUT.PUT_LINE(V_VAR(I) (J));
END LOOP;
END LOOP;
END;

 

posted @ 2012-07-31 00:58  全威儒  阅读(1337)  评论(0编辑  收藏  举报