CREATE TYPE accounttype AS OBJECT( no varchar2(10), name varchar2(10), balance number(10), dob date, member function age return number );
CREATE TYPE BODY accounttype AS
MEMBER FUNCTION age RETURN NUMBER
AS
BEGIN
RETURN FLOOR(MONTHS_BETWEEN(sysdate,dob)/12);
END age;
END;
/
CREATE TYPE account_branchtype AS OBJECT( account REF accounttype, branch varchar2(10) );
create type account_branchtabletype as table of account_branchtype;
create type stafftype as object(staff_id varchar2(20),name varchar2(20) ,sal number(20), other_details varchar2(20) , emp8 account_branchtabletype ,dob date , member function getage return number);
create or replace type body stafftype as member function getage return number
as
begin
return(round((sysdate-dob)/365));
end getage;
end;
/
create table stafftable of stafftype nested table emp8 store as relaccount_branch8;
insert into stafftable values(stafftype('S01','Captain','account',20000,'abc','24-apr-1993'));
insert into stafftable values(stafftype('S02','Thor','manager',30000,'pqr','14-jun-1993'));
insert into account_branchtable values('B01','manager','andheri',stafftabletype(stafftype('S01','Captain','account',20000,'abc','24-apr-1993')));
insert into account_branchtable values('B02','asst manager','sion',stafftabletype(stafftype('S02','Thor','manager',30000,'pqr','14-jun-1993')));
尝试将数据插入Stafftable时,错误显示为inconsistent datatypes: expected schema.ACCOUNT_BRANCHTABLETYPE got CHAR
。
小提琴= https://dbfiddle.uk/zDdqEJdx。
1条答案
按热度按时间dbf7pr2w1#
您没有表
account_branchtable
(您可能也不需要它)。您可能需要创建一个
REF
的集合:然后创建您的人员类型:
然后创建表:
然后您可以插入具有巢状表格值的人员:
fiddle