Search code examples
oracleoracle11gtemp-tables

Check to see if a Temporary Table exists


How do I check to see if an Oracle temporary table exists? I do not see the table when querying ALL_TABLES or USER_TABLES when I know it exists.

Also, to make sure I understand temporary tables, if created with ON COMMIT DELETE ROWS, the table will always exist, but the data will be deleted when the session ends? Is a session referring to when a connection is closed?


Solution

  • A temporary table will be listed in USER_TABLES if you own it and in ALL_TABLES if you have privileges on the table. It will be listed in DBA_TABLES if it exists in the database but you may not have privileges to query DBA_TABLES. If the table exists in the database but it is not in ALL_TABLES, that implies that the current user does not have privileges on the temporary table.

    Yes, a temporary table will always exist (once it is created, of course). When you specify ON COMMIT DELETE ROWS, the data in the temporary table will be removed when the transaction completes (either committing or rolling back). Each session will always only see the data that it has inserted into the table but when you specify ON COMMIT DELETE ROWS you're further limiting the time that the data exists to the current transaction.