我在Oracle中初始化REF值时遇到问题。当我尝试在构造函数中设置它们时,无论我如何尝试它都会出错。有没有办法在这样的情况下建造他们?
CREATE TYPE tSomething AS OBJECT (
Name Varchar(30)
);
CREATE TYPE tSomethingElse AS OBJECT (
Something REF tSomething
);
答案 0 :(得分:0)
Ref是现有对象的唯一标识符。您必须创建对象表以获取此唯一标识符。
CREATE TYPE tSomething AS OBJECT (
Name Varchar(30)
);
create table tSomething_table of tSomething;
CREATE TYPE tSomethingElse AS OBJECT (
Something REF tSomething
);
declare
tSomethingElse_obj tSomethingElse;
tSomething_ref REF tSomething;
tSomething_obj tSomething;
begin
-- insert objects into tSomething_table
insert into tSomething_table values('abc');
insert into tSomething_table values('yyy');
-- get ref one object.
select ref(p) into tSomething_ref from tSomething_table p where p.name = 'abc';
-- initialize tSomethingElse_obj;
tSomethingElse_obj := new tSomethingElse(tSomething_ref);
-- extract get real tSomething object from ref
select deref(tSomething_ref) into tSomething_obj from dual;
end;