oracle type类型

--创建类型说明***********************************************************

create or replace type dept_type as object(

--成员变量

    h_deptno number(2),

    h_dname  varchar2(14),

    h_loc varchar2(13),

--成员函数、过程

   member procedure changedept(name in varchar2,loc in varchar2),

   member function getdeptno return number,

   member function gedtname   return varchar2,

   member function getloc    return varchar2);

--类型创建完成

--创建类型包体

create or replace type body dept_type as

member procedure changedept(name in varchar2,loc in varchar2) is

begin

  h_dname := name;

  h_loc   := loc;

end changedept;

member function getdeptno return number as

begin

return h_deptno;

end getdeptno;

member function gedtname return varchar2 as

begin

return h_dname;

end gedtname;

member function getloc return varchar2 as

begin

return h_loc;

end getloc;

end;

--包体创建完毕-----------------------

--使用类型

declare

 dept1 dept_type;

begin

  dept1 := dept_type(10,'chenchaoyang','chenchaoyang');

  dept1.changedept('supan','supan');

  dbms_output.put_line(dept1.getdeptno);

  dbms_output.put_line(dept1.getloc);

end;

--调用完毕*******************************************************

你可能感兴趣的:(oracle type)