【发布时间】:2022-11-20 03:31:19
【问题描述】:
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。
【问题讨论】:
-
请不要close a question 然后再次有效地提出相同的问题(信息略少)。
-
Sadiq——这里的观众对从事浪费读者时间的行为的新用户非常敏感。
标签: sql oracle object-oriented-database