pl/sql学习4——嵌套表

嵌套表于pl/sql表类似,此外嵌套表还可以做为数据库表的列的类型

CREATE OR REPLACE

PROCEDURE PR_NESTEDTABLE_VARIABLE
AS
BEGIN
  declare
    cursor DEPT_CUR is select rownum,DEPTNO, DNAME,LOC from DEPT;
    type NAME_TYPE is table of DEPT.DNAME%type;
    DNAME_TAB NAME_TYPE := NAME_TYPE();
    /*需要初始化,不然会报错*/
    V_NAME DEPT.DNAME%type;
BEGIN
  FOR ITEM IN DEPT_CUR
  LOOP
    DNAME_TAB.extend;
    /*需要扩展,不然会报错*/
    DNAME_TAB(ITEM.rownum):=ITEM.DNAME;
  END LOOP;
 
  FOR i IN 1..DNAME_TAB.count
  LOOP
    DBMS_OUTPUT.PUT_LINE('名字为:'||dname_tab(i));
  END LOOP;
END;

END PR_NESTEDTABLE_VARIABLE;


 

----------------------------------------------------------------------------------------------------

create or replace type dept_type as object(

no number,

name varchar2(200)

);

create  or replace type emp_array is table of dept_type;

create table department(

deptno number,

emp emp_array

)nested table emp_array store as emp_array;

你可能感兴趣的:(数据库,object,table,扩展,nested)