CREATE OR REPLACE TYPE CURSOR AS OBJECT(
code varchar2(20),
className varchar2(30),
teach1 Teacher,
maximumPupils number,
maximumHours number,
CONSTRUCTOR FUNCTION cursor(code varchar2, className varchar2, passport Teacher, maximumPupils number, maximumHours number) RETURN SELF AS RESULT
)NOT FINAL;
CREATE OR REPLACE TYPE BODY CURSOR
AS
CONSTRUCTOR FUNCTION cursor(code varchar2, className varchar2, passport Teacher, maximumPupils number, maximumHours number) RETURN SELF AS RESULT
IS
BEGIN
SELF.code := code;
SELF.className := className;
SELF.passport:=passport;
SELF.maximumPupils := maximumPupils;
SELF.maximumHours := maximumHours;
END;
------------------------
CREATE TABLE SubjectClass OF Cursor;
-----------------------------------------
BEGIN
insert into SubjectClass values(1,'Class 1','43345678F',30,55);
END;
我已经尝试了以下所有内容(包括使用完整的构造函数引用),只使用了我愿意插入的教师对象的atribute .passport或引用它所在的另一个表(此护照号码以前存在于另一个名为Teachers的对象类型表中:
INSERT INTO SubjectClass VALUES(' 1',' Class 1',Teacher.passport(' 12345678A'),20,25);
INSERT INTO SubjectClass值(1,' Class 1',' 43345678F',30,55);
请帮助,我很快就会接受测试。
答案 0 :(得分:0)
假设您有以下TYPE:
AndroidMainifest
cursor_的TYPE BODY代码看起来像......
create or replace type teacher as object (
passport varchar2( 32 )
, something varchar2( 64 )
, another varchar2( 64 )
)
/
create or replace type cursor_ as object (
code varchar2(20)
, className varchar2(30)
, teacher_ teacher
, maximumPupils number
, maximumHours number
, constructor function cursor_ (
code varchar2
, className varchar2
, teacher_ teacher
, maximumPupils number
, maximumHours number
) return self as result
) not final
/
请注意,TYPE BODY有2" end;"线。由于一个"结束"不见了。
现在您可以为cursor_对象创建一个表,并插入一些测试数据:
create or replace type body cursor_
as
constructor function cursor_ (
code varchar2
, className varchar2
, teacher_ teacher
, maximumPupils number
, maximumHours number
) return self as result
as
begin
self.code := code ;
self.className := className ;
self.teacher_ := teacher_ ;
self.maximumPupils := maximumPupils ;
self.maximumHours := maximumHours ;
return ;
end;
end;
/
主题类表的示例查询:
create table subjectclass of cursor_ ;
begin
insert into subjectclass values (
new cursor_ ( 1, 'class1', new teacher( 'AA1100BB', 'something1', 'another1' ), 100, 16 )
);
insert into subjectclass values (
new cursor_ ( 2, 'class2', new teacher( 'BB2211CC', 'something2', 'another2' ), 120, 25 )
);
end ;
/
请参阅dbfiddle here。