当前位置: 代码迷 >> Oracle管理 >> 解释“TYPE dept_table_type IS TABLE OF departments.department_name%TYPE INDEX BY PL,该怎么解决
  详细解决方案

解释“TYPE dept_table_type IS TABLE OF departments.department_name%TYPE INDEX BY PL,该怎么解决

热度:80   发布时间:2016-04-24 05:30:04.0
解释“TYPE dept_table_type IS TABLE OF departments.department_name%TYPE INDEX BY PL
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 一样。
  相关解决方案