Adsense Ad

Thursday 25 May 2017

Oracle: ORA-00942 Error Message

ORA-00942 Error Message

Learn the cause and how to resolve the ORA-00942 error message in Oracle.

Description

When you encounter an ORA-00942 error, the following error message will appear:
  • ORA-00942: table or view does not exist

Cause

You tried to execute a SQL statement that references a table or view that either does not exist, that you do not have access to, or that belongs to another schema and you didn't reference the table by the schema name.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

If this error occurred because the table or view does not exist, you will need to create the table or view.
You can check to see if the table exists in Oracle by executing the following SQL statement:
SELECT *
FROM all_objects
WHERE object_type IN ('TABLE','VIEW')
AND object_name = 'OBJECT_NAME';
For example, if you are looking for a suppliers table, you would execute:
SELECT *
FROM all_objects
WHERE object_type IN ('TABLE','VIEW')
AND object_name = 'SUPPLIERS';

Option #2

If this error occurred because you do not have access to the table or view, you will need to have the owner of the table/view, or a DBA grant you the appropriate privileges to this object.

Option #3

If this error occurred because the table/view belongs to another schema and you didn't reference the table by the schema name, you will need to rewrite your SQL to include the schema name.
For example, you may have executed the following SQL statement:
SELECT *
FROM suppliers;
But the suppliers table is not owned by you, but rather, it is owned by a schema called app, you could fix your SQL as follows:
SELECT *
FROM app.suppliers;
If you do not know what schema the suppliers table/view belongs to, you can execute the following SQL to find out:
SELECT owner
FROM all_objects
WHERE object_type IN ('TABLE','VIEW')
AND object_name = 'SUPPLIERS';
This will return the schema name who owns the suppliers table.

No comments: