1.固定数组
DECLARE
TYPE V1 IS VARRAY(20) OF VARCHAR2(20);
MY_V V1 :=V1('A','B','C','D','E');
BEGIN
FOR I IN 1..MY_V.COUNT LOOP
DBMS_OUTPUT.PUT_LINE(MY_V(I));
END LOOP;
END;
2.可变长数组
DECLARE
TYPE V1 IS TABLE OF NUMBER(3) index by binary_integer;
V V1;
BEGIN
FOR I IN 1..20 LOOP
V(I):=I;
DBMS_OUTPUT.PUT_LINE(V(I));
END LOOP;
END;
3.二维数组
DECLARE
TYPE V1 IS TABLE OF NUMBER index by binary_integer;
TYPE V2 IS TABLE OF V1 index by binary_integer;
V V2;
BEGIN
FOR I IN 1..20 LOOP
FOR N IN 1..20 LOOP
V(I)(N):=N;
DBMS_OUTPUT.PUT_LINE(V(I)(N));
END LOOP;
END LOOP;
END;
使用数组输出以下格式的数列:
DECLARE
TYPE V1 IS TABLE OF NUMBER index by binary_integer;
TYPE V2 IS TABLE OF V1 index by binary_integer;
V V2;
BEGIN
FOR I IN 1..10 LOOP
FOR N IN 1..10 LOOP
V(I)(N):=0;
END LOOP;
END LOOP;
V(1)(1):=1;
DBMS_OUTPUT.PUT_LINE(V(1)(1));
FOR I IN 2..10 LOOP
V(I)(1):=1;
DBMS_OUTPUT.PUT(V(I)(1)||' ');
FOR N IN 2..I LOOP
V(I)(N):=(V(I-1)(N-1)+V(I-1)(N));
DBMS_OUTPUT.PUT(V(I)(N)||' ');
END LOOP;
DBMS_OUTPUT.PUT_LINE('');
END LOOP;
END;