This is one of those questions that makes it obvious what a newbie you are :-/
Is it possible to get a REF for a local object that is not in a table (yet)?
If I (could) return the REF from a function and the object leaves scope, does the object persist?
My plan was for a member function to populate a newly-created, empty object, and return a REF to it. The corresponding object would then be INSERTed into an object table.
Is this an assumption of Oracle's implementation of Object Types -- that they will always be stored in a table somewhere?
I have to use a REF because otherwise I have self-reference with no indirection. :-(
I'm not sure I follow all of what you are trying to achieve but I think I have a couple ideas around it.
You can get a ref to a local object like this:
my_obj my_obj_type := my_obj_type (null);
my_obj_ref ref my_obj_type;
select ref(my_obj) into my_obj_ref from dual;
I think what you want is a member function that returns a reference to itself.
I would expect that you could try something like the above within the member function and return the resulting ref. I have not tried this though.
My reading of the docs was that REF expects a correlation variable, not an object. In other words, it needs to be in a table somewhere. :-(
ie. DEREF(REF(i)) == object != i
But I will try your suggestion!
If you are using a PK-REF based object view or table, you can use the MAKE_REF function to get a REF to an object that is not yet persistently stored.
If you are using system-generated OIDs you cannot get a REF until it is stored in a table.
if you use object views instead of object tables, it's as easy to construct a 'self-reference' attribute as an other REF attribute, use MAKE_REF:
create or replace view V_My_View
with object identifier (key1, key2, ...)
, make_ref(V_My_View, t.key1, t.key2, ...) as selfRef
from T_My_Table t