Check if a Table Exists in Oracle

In Oracle Database, there are a number of views that we can query to find out whether a table exists.

Example

For example, USER_TABLES describes the relational tables owned by the current user.

SELECT TABLE_NAME 
FROM USER_TABLES 
WHERE TABLE_NAME = 'COUNTRIES';

Result:

COUNTRIES

In this example, I checked to see if there’s a relational table called COUNTRIES that is owned by the current user.

We could adjust this query to only return the count:

SELECT COUNT(TABLE_NAME)
FROM USER_TABLES 
WHERE TABLE_NAME = 'COUNTRIES';

Result:

1

In that case, the table name exists and so the count is 1.

Here’s what happens when the table doesn’t exist:

SELECT COUNT(TABLE_NAME)
FROM USER_TABLES 
WHERE TABLE_NAME = 'USERS';

Result:

0

The following table lists other views that contain information about tables in Oracle Database.

ViewDescription
USER_TABLESDescribes the relational tables owned by the current user (this view is used in the above example).
ALL_TABLESDescribes the relational tables accessible to the current user.
DBA_TABLESDescribes all relational tables in the database.
USER_ALL_TABLESDescribes the object tables and relational tables owned by the current user.
DBA_ALL_TABLESDescribes all object tables and relational tables in the database.
ALL_ALL_TABLESDescribes the object tables and relational tables accessible to the current user.