日期:2014-05-16  浏览次数:20477 次

创建自定义类型样例
create or replace procedure type_procedure
AS
i_count integer;
begin
  select count(*) into i_count from user_objects t where t.OBJECT_TYPE ='TYPE' and t.OBJECT_NAME = upper('type_name');
    if i_count>0 then
        EXECUTE IMMEDIATE 'drop type type_name';
    end if;
end type_procedure;
/
call type_procedure();
drop procedure type_procedure;

create or replace type type_name1 as object
(
  beginTime Date,
  level5num  INTEGER
)
/
/**创建嵌套表,表中每个元素数据类型是type_name1**/
create or replace type nested_name1 as table of type_name1;/

CREATE OR REPLACE TYPE type_name2 AS OBJECT
(
  NODENAME             VARCHAR2(512),
  REGIONNAME      VARCHAR2(512)
);
/
/**创建嵌套表,表中每个元素数据类型是type_name2**/
CREATE OR REPLACE TYPE nestedtable_LIST AS TABLE OF type_name2;
/
/**创建嵌套表,表中每个元素数据类型是NUMBER(10)**/
CREATE OR REPLACE TYPE nestedtable_LIST AS TABLE OF NUMBER(10);
/