SQL Error: ORA-00942 table or view does not exist

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16129912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:55:49  来源:igfitidea点击:

SQL Error: ORA-00942 table or view does not exist

sqloracle11g

提问by user2304042

I use SQL developer and i made a connection to my database with the system user, after I created a user and made a another connection with that user with all needed privileges.

I use SQL developer and i made a connection to my database with the system user, after I created a user and made a another connection with that user with all needed privileges.

But when I try to proceed following I get the SQL Error

But when I try to proceed following I get the SQL Error

ORA-00942 table or view does not exist.:

ORA-00942 table or view does not exist.:



INSERT INTO customer (c_id,name,surname) VALUES ('1','Micheal','Hymanson')

回答by jake stayman

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.

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:

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:

Then, execute this insert statement as user2:

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

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

The result will be "ORA-00942: table or view does not exist" even though user2does have insert and select privileges on user1.customertable 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;

回答by rs'

either the user doesn't have privileges needed to see the table, the table doesn't exist or you are running the query in the wrong schema

either the user doesn't have privileges needed to see the table, the table doesn't exist or you are running the query in the wrong schema

does the table exist?

does the table exist?

select owner, 
       object_name 
from dba_objects 
where object_name = any ('CUSTOMER','customer');

what privileges did you grant?

what privileges did you grant?

grant select, insert on customer to user;

are you running the query against the owner from the first query?

are you running the query against the owner from the first query?

回答by user2529066

You cannot directly access the table with the name 'customer'. Either it should be 'user1.customer' or create a synonym 'customer' for user2 pointing to 'user1.customer'. hope this helps..

You cannot directly access the table with the name 'customer'. Either it should be 'user1.customer' or create a synonym 'customer' for user2 pointing to 'user1.customer'. hope this helps..

回答by chakeda

Case sensitive Tables (table names created with double-quotes) can throw this same error as well. See this answerfor more information.

Case sensitive Tables (table names created with double-quotes) can throw this same error as well. See this answerfor more information.

Simply wrap the table in double quotes:

Simply wrap the table in double quotes:

INSERT INTO "customer" (c_id,name,surname) VALUES ('1','Micheal','Hymanson')

回答by TechMaze

Here is an answer: http://www.dba-oracle.com/concepts/synonyms.htm

Here is an answer: http://www.dba-oracle.com/concepts/synonyms.htm

An Oracle synonym basically allows you to create a pointer to an object that exists somewhere else. You need Oracle synonyms because when you are logged into Oracle, it looks for all objects you are querying in your schema (account). If they are not there, it will give you an error telling you that they do not exist.

An Oracle synonym basically allows you to create a pointer to an object that exists somewhere else. You need Oracle synonyms because when you are logged into Oracle, it looks for all objects you are querying in your schema (account). If they are not there, it will give you an error telling you that they do not exist.

回答by Mohit Jariwal

I am using Oracle Database and i had same problem. Eventually i found ORACLE DB is converting all the metadata (table/sp/view/trigger) in upper case.

I am using Oracle Database and i had same problem. Eventually i found ORACLE DB is converting all the metadata (table/sp/view/trigger) in upper case.

And i was trying how i wrote table name (myTempTable) in sql whereas it expect how it store table name in databsae (MYTEMPTABLE). Also same applicable on column name.

And i was trying how i wrote table name (myTempTable) in sql whereas it expect how it store table name in databsae (MYTEMPTABLE). Also same applicable on column name.

It is quite common problem with developer whoever used sql and now jumped into ORACLE DB.

It is quite common problem with developer whoever used sql and now jumped into ORACLE DB.