Read Inconsistency?

Riddle me this: Can an object exist in all_objects before it is created?
Well no, of course not.
I was under the assumption that if you create a table with a select-statement, a CTAS – Create Table As Select – that the select was executed prior to the creation of the table. Read Consistency dictates that the result set returned by a Select statement, returns the values as of that particular moment in time.

....

To demonstrate this Tom Kyte has an example similar to this:

SQL> var rc refcursor
SQL> create table t
2 as
3 select *
4 from dual
5 /

Table created.

SQL> exec open :rc for select * from t

PL/SQL procedure successfully completed.

SQL> delete from t
2 /

1 row deleted.

SQL> commit
2 /

Commit complete.

SQL> print

D
-
X

SQL>

The shortest possible script to demonstrate Read Consistency. The result you see after the Delete followed by a Commit, are returned by the Ref Cursor, which was executed prior to the delete.

Odd or at least Remarkable?

Isn’t this odd then?

SQL> drop table t purge
2 /

Table dropped.

SQL> select owner, object_name
2 from all_objects
3 where owner = 'ALEX'
4 and object_name = 'T'
5 /

no rows selected

SQL> create table t
2 as
3 select *
4 from all_objects
5 /

Table created.

SQL> select owner, object_name
2 from t
3 where owner = 'ALEX'
4 and object_name = 'T'
5 /

OWNER OBJECT_NAME
------------------------------ -----------
ALEX T

SQL>

How is it possible that an entry is alread present in the newly created Table T, which should be a copy of ALL_OBJECTS? Apparently, when you create a table, an entry in the datadictionary is created prior to executing the Select-statement…. strange, don’t you think?
That goes to show it, the datadictionary is "special".

8 Comments

  1. Alex Nuijten October 10, 2006
  2. Sunil Gidwani October 9, 2006
  3. Alex Nuijten September 13, 2006
  4. Andre Crone September 12, 2006
  5. Edwin van Meerendonk September 11, 2006
  6. Gary September 11, 2006
  7. Michael Friedman September 8, 2006
  8. Jo Olluyn September 8, 2006