Database 初始化对象类型构造函数oracle
我正在用oracle开发一个数据库。 我已经创建了一个超类型,即answer和一个子类型closed\u answer。我添加了一个字段“type”来区分它们,但我希望该字段在构造函数中初始化,以便在表中插入元组时不插入该字段。我已经尝试过了,但是当我在表中插入元组时,我必须指定类型,但我不应该这样做。我错在哪里Database 初始化对象类型构造函数oracle,database,oracle,Database,Oracle,我正在用oracle开发一个数据库。 我已经创建了一个超类型,即answer和一个子类型closed\u answer。我添加了一个字段“type”来区分它们,但我希望该字段在构造函数中初始化,以便在表中插入元组时不插入该字段。我已经尝试过了,但是当我在表中插入元组时,我必须指定类型,但我不应该这样做。我错在哪里 create type answertyp as object( id integer, text varchar2(50), type varchar2(25), const
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
或者从SQL语句中删除id
:
insert into answer select closed_answertyp('ten') from dual;