Ошибка 942 oracle

If you’ve used Oracle, you’ve probably gotten the helpful message «ORA-00942: Table or view does not exist». Is there a legitimate technical reason the message doesn’t include the name of the missing object?

Arguments about this being due to security sound like they were crafted by the TSA. If I’m an attacker, I’d know what table I just attempted to exploit, and be able to interpret this unhelpful message easily. If I’m a developer working with a complex join through several layers of application code, it’s often very difficult to tell.

My guess is that when this error was originally implemented, someone neglected to add the object name, and now, people are afraid it will break compatibility to fix it. (Code doing silly things like parsing the error message will be confused if it changes.)

Is there a developer-friendly (as opposed to recruiting your DBA) way to determine the name of the missing table?


Although I’ve accepted an answer which is relevant to the topic, it doesn’t really answer my question: Why isn’t the name part of the error message? If anyone can come up with the real answer, I’ll be happy to change my vote.

Lalit Kumar B's user avatar

Lalit Kumar B

47.6k13 gold badges97 silver badges124 bronze badges

asked Sep 5, 2008 at 17:45

erickson's user avatar

3

You can set an EVENT in your parameter file (plain text or spfile) to force Oracle to dump a detailed trace file in the user_dump_dest, the object name might be in there, if not the SQL should be.

EVENT=»942 trace name errorstack level 12″

If you are using a plain text file you need to keep all your EVENT settings on consecutive lines. Not sure how that applied to spfile.

answered Sep 5, 2008 at 17:51

Ethan Post's user avatar

Ethan PostEthan Post

3,0203 gold badges28 silver badges27 bronze badges

1

SQL*Plus does tell you the table that doesn’t exist. For example:

SQL> select
  2     *
  3  from
  4     user_tables a,
  5     non_existent_table b
  6  where
  7     a.table_name = b.table_name;
   non_existent_table b
   *
ERROR at line 5:
ORA-00942: table or view does not exist

Here it shows that the name of the missing table and the line number in the SQL statement where the error occurs.

Similarly, in a one-line SQL statement you can see the asterisk highlighting the name of the unknown table:

SQL> select * from user_tables a, non_existent_table b where a.table_name = b.table_name;
select * from user_tables a, non_existent_table b where a.table_name = b.table_name
                             *
ERROR at line 1:
ORA-00942: table or view does not exist

In terms of your question, I guess the reason the error message doesn’t include the name of the table is that the error message itself needs to be static text. The line number and location in the line of the error is clearly passed back to SQL*Plus (somehow).

answered Sep 9, 2008 at 15:11

Nick Pierpoint's user avatar

Nick PierpointNick Pierpoint

17.6k9 gold badges46 silver badges74 bronze badges

4

I would disagree with the opinion, that SQL+ lets you understand which table name is unacceptable. True, it helps in direct DML, although parsing it is very hard. But when it comes to dynamic, we get no help:

SQL> begin
  2  execute immediate 'insert into blabla values(1)';
  3  end;
  4  /
begin
*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at line 2

answered Jan 31, 2011 at 12:32

If you are using a SQL browsing tool like TOAD or TORA it will help you with ORA errors by highlightling or pointing moving the cursor to where you made your error.

Copy and paste your SQL in to one of these tools to help. You may also find the analyse info available useful too.

answered Sep 5, 2008 at 17:55

Mark Nold's user avatar

Mark NoldMark Nold

5,6487 gold badges31 silver badges33 bronze badges

1

If its not a huge statement, then the easiest way is just to check the data dictionary,

SQL> select * from xx,abc;
select * from xx,abc
                 *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select owner,table_name from all_tables where table_name in ('XX','ABC');

OWNER                          TABLE_NAME
------------------------------ ------------------------------
MWATSON                        XX

SQL> 

This isn’t ideal, but short of going and examining trace files, I’m not sure how else to do it.

answered Sep 6, 2008 at 0:58

Matthew Watson's user avatar

Matthew WatsonMatthew Watson

14.1k9 gold badges62 silver badges82 bronze badges

I’ve never had a problem with interpreting Oracle error messages. Part of the reason is that every interactive tool I’ve seen for developing SQL for Oracle helpfully points to the location the query went wrong. That includes SQL*Plus, as others have noted, and the Perl DBI module:

$ exec_sql.pl 'select * from daul'
DBD::Oracle::db prepare failed: ORA-00942: table or view does not exist (DBD ERROR: error possibly near <*> indicator at char 14 in 'select * from <*>daul') [for Statement "select * from daul"] at exec_sql.pl line 68.

Well, that is a bit hard to read since it’s all squished on one line. But a GUI tool would be able to point to the token where Oracle started having problems with the query. And given a bit of work on a parser, you could write a tool to pick out the offending table.

To answer the underlying question, Oracle errors don’t seem to be designed to work the way you expect. As far as I can tell, none of the the error messages in Oracle support variable text. Instead, Oracle returns two bits of information: an error number and a location where the error occurs. If you have proper tools, it’s pretty easy to diagnose an error with those pieces of data. It can be argued that Oracle’s system is nicer to tool creators than one which provides variable amounts of diagnostic data depending on the error. Imagine having to write a custom parser for all of Oracle’s error messages (including future errors) to highlight the offending location.

Sometimes including the table name would be misleading. Just knowing where things went wrong can be a huge help:

SQL> select * from where dummy = 'X';
select * from where dummy = 'X'
              *
ERROR at line 1:
ORA-00903: invalid table name

As for why Oracle chose to do thing this way, I have some speculations:

  1. IBM used this style of error message for System R, which Larry Ellison, Bob Miner and Ed Oates copied to build Oracle V2. (Backward compatibility.)

  2. Error number and location are the smallest possible representation of diagnostic information. (Parsimony.)

  3. As I indicated above, to simplify the creation of tools that connect to Oracle. (Interoperability.)

In any case, I don’t think you need to be a DBA to figure out which table doesn’t exist. You just need to use the proper tools. (And adjust your expectations, I suppose.)

answered Apr 21, 2009 at 0:03

Jon 'links in bio' Ericson's user avatar

6

Reason 1: Multi-lingual interface

There is a language-specific message configuration file for your database instance. Messages are pulled out of there and translated from the pure numeric version to the numeric+text version.

It was probably considered better to have the hardcoded strings, than to run the risk at runtime of having a mysterious failure due to an improperly formatted «%s» string.

(Not that I particularly agree with this POV, btw.)

Reason 2: Security

Right now you don’t particularly expose the internal workings of your application if you print a PHP, etc, dump of an Oracle error message to the browser.

Applications would be a bit more exposed if more detail were printed by default… For example, if citibank printed a more explanatory message.

(see disclaimer above, I would be happy to get more information in the error as well.)

answered Apr 21, 2009 at 3:54

Mark Harrison's user avatar

Mark HarrisonMark Harrison

298k125 gold badges333 silver badges465 bronze badges

1

@Matthew

Your query’s a start, but it might not work when you have multiple schemas. For example, if I log into our instance as myself, I have read access to all our tables. But if I don’t qualify the table name with the schema I’ll get an ORA-00942 for tables without synonyms:

SQL> select * from tools; 
select * from tools 
              * 
ERROR at line 1: 
ORA-00942: table or view does not exist 

The table still shows up in all_tables though:

SQL> select owner, table_name from all_tables where table_name = 'TOOLS'; 

OWNER                          TABLE_NAME 
------------------------------ ------------------------------ 
APPLICATION                    TOOLS 

@erikson
Sorry that doesn’t help much. I’m with Mark — I used TOAD.

answered Sep 7, 2008 at 13:07

Hobo's user avatar

HoboHobo

7,5365 gold badges40 silver badges50 bronze badges

Because this post is the top one found on stackoverflow when searching for «ORA-00942: table or view does not exist insert», I want to mention another possible cause of this error (at least in Oracle 12c): a table uses a sequence to set a default value and the user executing the insert query does not have select privilege on the sequence. This was my problem and it took me an unnecessarily long time to figure it out.

To reproduce the problem, execute the following SQL as user1:

create sequence seq_customer_id;

create table customer (
c_id number(10) default seq_customer_id.nextval primary key,
name varchar(100) not null,
surname varchar(100) not null
);

grant select, insert, update, delete on customer to user2;

Then, execute this insert statement as user2:

insert into user1.customer (name,surname) values ('michael','jackson');

The result will be «ORA-00942: table or view does not exist» even though user2 does have insert and select privileges on user1.customer table and is correctly prefixing the table with the schema owner name. To avoid the problem, you must grant select privilege on the sequence:

grant select on seq_customer_id to user2;

ORA-00942

ORA-00942: таблица или обзор не существуют

Причина:

Вводимая таблица или обзор не существует, или происходит ссылка на обзор когда требуется таблица. Существующие пользовательские таблицы не могут просматриваться запрашиванием словаря данных.

Действие:

Убедитесь, что спеллинг вашей таблицы или обзора правилен, не надо указывать таблицу где требуется обзор. Вводите всегда имя существующей таблицы или обзора.

Have you gotten an ORA-00942 error? I’ll explain the cause and the solution of the error in this article.

ORA-00942 Cause

The error message appears when you try to run an SQL statement:

ORA-00942: table or view does not exist

This happens for one of many reasons:

  • The statement references a table or view that does not exist
  • You do not have access to that table or view
  • The table or view belongs to a different schema and you did not refer to the schema name
  • You’re running Oracle 12c, using a sequence as a default value, but don’t have select privileges on the sequence.

The cause of the error should be the same in each database version. It shouldn’t matter if you’re getting this “table or view does not exist” error in Oracle 10g, Oracle 11g, or Oracle 12c.

The only difference is the sequence-related cause mentioned above because one of the new features in Oracle 12c is the ability to use a sequence as a default value.

Let’s take a look at some of the solutions, depending on the cause.

There are several solutions for this error, depending on the cause.

First, check that the table exists. You can do that by running this query:

SELECT owner, object_name, object_type
FROM all_objects
WHERE object_type IN ('TABLE','VIEW')
AND object_name = 'OBJECT_NAME';

Substitute the word OBJECT_NAME with your table name. It must be in upper case as well.

SELECT owner, object_name, object_type
FROM all_objects
WHERE object_type IN ('TABLE','VIEW')
AND object_name = 'CLASS';

Results:

OWNER OBJECT_NAME OBJECT_TYPE
SYSTEM CLASS TABLE

If your table does not show, then it does not exist, and you’ll need to look into why it doesn’t exist.

Or, if you’re using SQL Developer, you can check the table exists by expanding the Tables section on the left side of the screen. If you see the table there, it means it exists and you’re the owner.

Class Table in Tree Explorer

Next, check the owner of the table.

If the table exists, and you’re getting this error, then check the owner of the table.

You can use the same query as above, and take note of the owner of the table.

If the owner is not you, then you’ll need to contact the database administrator to request privileges to select from the table (or to perform whatever operation you were trying to do).

Finally, check your query to ensure it refers to the correct schema.

If the table or view exists, and you have the privileges you need, then it could be an issue in your query.

Let’s say your username is “bob”. You have a set of tables under the “bob” schema.

If you want to select from a table called “employee”, and this is in the “mary” schema, it is owned by “mary”. When you refer to the table (such as in a SELECT statement), you might have a query like this:

SELECT *
FROM employee;

You might get the ORA-00942 error at this point. This is because Oracle is looking in your schema, or “bob”, for an employee table. But, it doesn’t exist in your schema – it’s in the “mary” schema.

So, you’ll need to change your query to include the schema name.

SELECT *
FROM mary.employee;

This query should run without the error.

Oracle 12c and Sequences

If you’re getting the ora-00942 table or view does not exist in Oracle 12c, then it could be caused by this situation:

  • Another user has a table and a sequence
  • One of the columns in the table has a default value of the sequence.nextval
  • You have the right privileges on the table

However, you can get this error if you’re querying this table and don’t have select privileges on the sequence.

Consider this situation:

As user “bob”:

CREATE SEQUENCE sequence_book_id;

CREATE TABLE books (
  book_id NUMBER(5) DEFAULT sequence_book_d.nextval PRIMARY KEY,
  title VARCHAR2(100)
);

GRANT SELECT, INSERT, UPDATE, DELETE ON books TO "mary";

Now, logged in as “mary”:

INSERT INTO books (title)
VALUES ('The Adventure');

You’ll get an ORA-00942 error here.

The reason for this is that “mary” doesn’t have SELECT privileges on sequence_book_id. She has INSERT privileges on the table, but as a result of inserting into the table, a SELECT on the sequence is called, which causes this error.

To resolve this, grant SELECT privileges to the second user.

GRANT SELECT ON sequence_book_id TO mary;

That should now work.

I hope this article has helped you resolve the ORA-00942 error.

While you’re here, if you want an easy-to-use list of the main features in Oracle SQL, get my SQL Cheat Sheet here:

The ORA-00942: table or view does not exist error indicates that you are trying to run a SQL query that refers to a non-existent table or view, or that the appropriate permissions and privileges do not exist, or that the table and view names are misspelt. The referencing table or view does not exist, or you are attempting to use a table without the appropriate permissions or privileges. Check that the table and view names are correctly spelt, and that the view is not being used in areas where a table is required.

The table or view is either not created or it is removed from the database. When you try to execute the table, oracle shows error message as table or view does not exist. It’s possible that the database user lacks the necessary permissions to execute the table or view. If Oracle cannot find the table in the database, the error “ORA-00942: table or view does not exist” will be thrown.

The table or view did not exist because it was never created, which is a typical cause of the “ORA-00942: table or view does not exist.” error. If you’re not sure whether a view, table, or synonym exists, use the data dictionary to get a list of all tables and views. You’re referring to a table or view in another schema that wasn’t created by you. You must refer to the table by its schema name when running the query from another schema.

ORA-00942: table or view does not exist error occurs if the table or view does not exist in the database or that the appropriate permissions and privileges do not exist, or that the table and view names are misspelt.

When the ORA-00942 error occurs

If the table or view is not created or removed from the database, the Oracle error “ORA-00942: table or view does not exist” occurs. The error will be thrown if the table or view does not have the necessary permissions and privileges. The employee table is not created in the database in the following example. The select sql query is executed on the database’s employee table. The employee table could not be found in the Oracle database. As a result, Oracle throws an error stating that the table or view does not exist.

select * from emp;
Error starting at line : 35 in command -
select * from emp;
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"

Root Cause

The table or view that was requested does not exist in the database. The database table or view was either not created or was removed. The sql query searches for a table or view in the database objects list. The SQL error will be thrown because the table or view could not be found in the database. It’s possible that the user that executes the sql query lacks the necessary table or view permissions. If the table does not exist in the database, the user does not have the necessary privileges and permissions to execute, or the table name is misspelt, the ORA-00942: table or view does not exist error will be thrown.

Solution 1

The table or view name in the sql query may be misspelt. Check the table and view names in the sql query. If the name is misspelt, update it to the correct name in the sql query. The misspelt table or view will not be present in the database sql. The ORA-00942: table or view does not exist error will be thrown. Oracle searches the database for the specified table name. The table with the misspelt name does not exist in the database. The error will be thrown by the Oracle database.

Solution 2

The error is typically caused by a table or view not being created or deleted from the database. If the table or view does not already exist in the database, create it. The sql query will run without the error “ORA-00942: table or view does not exist” when the table or view is created in the database. This query cannot be executed if the table has been deleted. Remove the sql query that will be executed in the database. If the table is accidentally removed, recreate it and then run the query to resolve the error.

create table employee
(
empid integer primary key,
me-name varchar2(100)
);

select * from employee;

Solution 3

The table or view can be created using multiple schemas. It’s possible you’re switching schemas. The sql query was unable to find the table or view from the existing schema. In this case, the schema name should appear before the table name. The current schema must have the necessary permissions in order to call a table or view from another schema. The schema name should be prefixed by the name of the table or view. Before running the table from another schema, the necessary permissions should be granted.

select * from <schema_name>.<tablename>;

select * from hr.employee;

Solution 4

When the view is created, the underlying table may be unavailable or removed, or it may not have the necessary permissions to execute. In this case, the error will be thrown. Check that the underlying database objects, such as tables, types, and sequences, are accessible and have the necessary permissions.

create table employee 
(
empid integer primary key,
empname varchar2(100)
);

create view emplist as select * from employee;

drop table employee;

select * from emplist;

Solution 5

If the table is created using a sequence that does not have sufficient permission to execute, the error will be thrown. The table is created using the sequence. If you insert a row into the table, the table will be unable to run the sequence and determine the next value to enter into the auto increment column.

create sequence seq_emp;
create table employee 
(
empid integer default seq_emp.nextval primary key,
empname varchar2(100)
);

insert into employee('Yawin');

The below permissions should be added to execute the sequence if an another user executes the insert statement.

grant select on seq_emp to emp2;

Понравилась статья? Поделить с друзьями:
  • Ошибка 9408 бмв е60
  • Ошибка 9681 форд фокус 2 рестайлинг
  • Ошибка 9681 ford focus 2
  • Ошибка 9672723 фольксваген
  • Ошибка 9406 соната