第一种方式:
1DECLARE
2 TYPE TBL_T IS TABLE OF VARCHAR2(30);
3 MY_TBL TBL_T := TBL_T(); --初始化
4BEGIN
5 FOR INX IN (SELECT ENAME FROM EMP) LOOP
6 MY_TBL.EXTEND; --扩展
7 MY_TBL(MY_TBL.LAST) := INX.ENAME;
8 END LOOP;
9 -- SELECT ENAME BULK COLLECT INTO MY_TBL FROM EMP;
10 FOR I IN MY_TBL.FIRST..MY_TBL.LAST LOOP
11 DBMS_OUTPUT.PUT_LINE('MY_TBL('||I||') = '||MY_TBL(I));
12 END LOOP;
13END;
2 TYPE TBL_T IS TABLE OF VARCHAR2(30);
3 MY_TBL TBL_T := TBL_T(); --初始化
4BEGIN
5 FOR INX IN (SELECT ENAME FROM EMP) LOOP
6 MY_TBL.EXTEND; --扩展
7 MY_TBL(MY_TBL.LAST) := INX.ENAME;
8 END LOOP;
9 -- SELECT ENAME BULK COLLECT INTO MY_TBL FROM EMP;
10 FOR I IN MY_TBL.FIRST..MY_TBL.LAST LOOP
11 DBMS_OUTPUT.PUT_LINE('MY_TBL('||I||') = '||MY_TBL(I));
12 END LOOP;
13END;
第二种方式:
用SELECT ... BULK COLLECT INTO... FROM...语法