DECLARE
TYPE dept_table_type
IS TABLE OF departments.department_name%TYPE
INDEX BY PLS_INTEGER;
my_dept_table dept_table_type;
loop_count NUMBER(2) := 10;
deptno NUMBER(4) := 0;
BEGIN
FOR i IN 1..loop_count LOOP
deptno := deptno + 10;
SELECT depatment_name INTO my_dept_table(i)
FROM departments
WHERE department_id = deptno;
END LOOP;
FOR i IN 1..loop_count LOOP
DBMS_OUTPUT.PUT_LINE(my_dept_table(i));
END LOOP;
END;
------解决方案--------------------
定义 DEPT_TABLE_TYPE 为一个类型【TABLE OF DEPARTMENTS.DEPARTMENT_NAME%TYPE】
然后在用它定义变量 MY_DEPT_TABLE
换句简单的话讲, MY_DEPT_TABLE 是一个数组,数组里面每一个元素是的类型和DEPARTMENTS.DEPARTMENT_NAME%TYPE 一样。