我正在 oracle 中开发一个数据库。我创建了一个超类型 answer 和一个子类型 closed_answer。我添加了一个字段“类型”来区分它们,但我希望这个字段在构造函数中初始化,以便在我在该表中插入一个元组时不插入这个字段。我试过了,但是当我在表 closed_answer 中插入一个元组时,我必须指定类型,但我不应该。我哪里错了?
create type answertyp as object(
id integer,
text varchar2(50),
type varchar2(25),
constructor function answertyp(self in out nocopy answertyp, text varchar2) return self as result) not final;
create type body answertyp is
constructor function answertyp(self in out nocopy answertyp, text varchar2) return self as result is
begin
self.text := text;
self.type:= 'answer';
return;
end;
end;
/
create type closed_answertyp under closed_answer(
constructor function closed_answertyp(self in out nocopy closed_answertyp, text varchar2) return self as result
) final;
create type body closed_answertyp is
constructor function closed_answertyp (self in out nocopy closed_answertyp, text varchar2) return self as result is
begin
self.text := text;
self.type := 'closed_answer';
return;
end;
end;
现在,如果我尝试这个查询,它说参数的数量是错误的。有什么帮助吗?谢谢
insert into answer select closed_answertyp(1, 'ten') from dual;
SQL 语句中的参数与构造函数中的参数不匹配。
添加id
到构造函数:
constructor function closed_answertyp (self in out nocopy closed_answertyp, id integer, text varchar2) return self as result is
或者id
从 SQL 语句中删除:
insert into answer select closed_answertyp('ten') from dual;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句