4 Replies Latest reply on May 17, 2011 10:41 PM by gaverill

    Get REF of object not in table?

      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. :-(

        • 1. Re: Get REF of object not in table?
          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.

          • 2. Re: Get REF of object not in table?
            Thanks Joe.

            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!
            • 3. Re: Get REF of object not in table?
              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.
              • 4. Re: Get REF of object not in 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
                  of TMyObject
                  with object identifier (key1, key2, ...)
                  select t.key1
                  ,        t.key2
                  ,        ...
                  ,        make_ref(V_My_View, t.key1, t.key2, ...) as selfRef
                  ,        ...
                  from   T_My_Table t
                  where ...
                Hope this helps.