ORACLE常用语法

--创建一个一维数组,输出数组内容
create or replace procedure TEST_5
IS
TYPE T_VARRAY IS VARRAY(5) OF NUMBER;
V_VARR T_VARRAY := T_VARRAY(1,2,3,4,5);
BEGIN
FOR I IN 1..V_VARR.COUNT LOOP
DBMS_OUTPUT.put_line(V_VARR(I));
END LOOP;
END;

--创建一个二维数组
create or replace procedure TEST_6
IS
TYPE T_VARRAY IS VARRAY(5) OF NUMBER;
TYPE T_T_VARRAY IS VARRAY(4) OF T_VARRAY;

V_VARR T_T_VARRAY := T_T_VARRAY(
T_VARRAY(1,2,3,4,5),
T_VARRAY(11,22,33,44,55),
T_VARRAY(111,222,333,444,555),
T_VARRAY(1111,2222,3333,4444,5555)
);
BEGIN
FOR I IN 1..V_VARR.COUNT LOOP
    FOR J IN 1..V_VARR(I).COUNT LOOP
        DBMS_OUTPUT.put_line(V_VARR(I)(J));
    END LOOP;
END LOOP;
END;

--创建一个索引表
create or replace procedure TEST_7
IS
TYPE T_TABLE IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
T_T_TABLE T_TABLE;

BEGIN
SELECT ROWNUM BULK COLLECT INTO T_T_TABLE FROM DEPT;
FOR I IN 1..T_T_TABLE.COUNT LOOP
DBMS_OUTPUT.put_line(T_T_TABLE(I));
END LOOP;
END;

你可能感兴趣的:(oracle,sql,J#)