Search code examples
databasedb2db2-luw

Does a table like user_tables (used in oracle) in db2 exist?


I know that syscat.tables exists in db2. I also tried to find the count in user_tables and I got the output this way:

db2 =>  select count(*) from user_tables

1
-----------
        999

  1 record(s) selected.

but I couldn't describe the table user_tables while I could describe any other table.

Example:

db2 => describe table user_tables

                                Data type                     Column
Column name                     schema    Data type name      Length     Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------

  0 record(s) selected.

SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table.  SQLSTATE=02000

Could you help me understand why this is happening?


Solution

  • DB2 has an Oracle compatibility mode which needs to be enabled for a database. As part of this users can opt to have Oracle data dictionary-compatible views created. One of the views is user_tables.

    Could you try the following (not tested):

    describe select * from user_tables
    

    This should return the schema for the result table which is that view.