1 Reply Latest reply: Sep 14, 2009 4:16 PM by gaverill RSS

    REF values not same

    722105
      Hi, I am new to object stuff. I have a simple question relating to REF values.

      -- create an object type:
      create or replace type book_typ as object ( Name varchar2(25))
      /

      -- create object table:
      create table books of book_typ;

      --insert 1 row into it
      insert into books values (book_typ('PL/SQL'));

      --display it:
      select * from books;
      NAME
      ---
      PL/SQL

      --display its REF value and its length (86 chars)
      select REF(A), length(reftohex(ref(a)) ) from books A;

      'REF(A) LENGTH(REFTOHEX(REF(A)))'
      ---------------------------------------------------------------------------------------------------------- ------------
      *00002802097142FB07B0F24332B36957F129CD289F1E09C21B881E4E8F8DFBE498FC34B3AC010003FE0000* *86*



      -- create 2nd table to contain this REF value:
      create table books_ref ( book_ref REF book_typ);

      -- save REF value of row in 1st table in 2nd table:
      insert into books_ref select ref(a) from books a;

      -- display value from 1st table using this saved REF value. Still OK:
      select A.* From books A where ref(a) in (select book_ref from books_ref);
      NAME
      --------
      PL/SQL

      -- display the saved REF value:
      select R.*, length(reftohex(r.book_ref)) from books_ref R;

      BOOK_REF LENGTH(REFTOHEX(R.BOOK_REF))
      -------------------------------------------------------------------------- ----------------------------
      *00002202087142FB07B0F24332B36957F129CD289F1E09C21B881E4E8F8DFBE498FC34B3AC* *74*



      Why these 2 REF values are different since they ? Their lengths are different also (86 vs 74 chars)?

      Thanks
        • 1. Re: REF values not same
          gaverill
          Think of an object reference as a binding between an object table or view and the primary key value(s) of an instance (row) in that table or view.

          Same table or view and same primary key values, then equivalent REFs.

          Different table or view or different primary key values, then different REFs.

          You have different tables, so despite the same primary key values, your REFs are different.

          Hope that helps...

          --- Edit

          My bad, I re-read the question and realized this doesn't explain it. "Nevermind..."

          Edited by: gaverill on Sep 14, 2009 2:15 PM