简体   繁体   English

SQL 错误:ORA-00942 表或视图不存在

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

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.我使用 SQL 开发人员并与系统用户建立了到我的数据库的连接,之后我创建了一个用户并与该用户建立了另一个连接,并具有所有需要的权限。

But when I try to proceed following I get the SQL Error但是当我尝试继续以下时,我收到 SQL 错误

ORA-00942 table or view does not exist.: ORA-00942 表或视图不存在。:


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

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.因为这篇文章是搜索“ORA-00942:表或视图不存在插入”时在stackoverflow上找到的最上面的一篇,所以我想提一下这个错误的另一个可能原因(至少在Oracle 12c中):表使用序列设置默认值,并且执行插入查询的用户对序列没有选择权限。 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 :要重现该问题,请以user1身份执行以下 SQL:

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 :然后,以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.结果将是“ORA-00942:表或视图不存在”,即使user2确实对user1.customer表具有插入和选择权限,并且正确地为表添加了架构所有者名称的前缀。 To avoid the problem, you must grant select privilege on the sequence:为避免此问题,您必须授予对序列的选择权限:

grant select on seq_customer_id to user2;

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?表存在吗?

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

What privileges did you grant?你授予了什么特权?

    grant select, insert on customer to user;

Are you running the query against the owner from the first query?您是否从第一个查询中针对所有者运行查询?

You cannot directly access the table with the name 'customer'.您不能直接访问名为“customer”的表。 Either it should be 'user1.customer' or create a synonym 'customer' for user2 pointing to 'user1.customer'.它应该是“user1.customer”,或者为指向“user1.customer”的 user2 创建同义词“customer”。 hope this helps..希望这可以帮助..

Case sensitive Tables (table names created with double-quotes) can throw this same error as well.区分大小写的表(用双引号创建的表名)也会抛出同样的错误。 See this answer for more information. 有关更多信息, 请参阅此答案

Simply wrap the table in double quotes:只需将表格用双引号括起来:

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

Here is an answer: http://www.dba-oracle.com/concepts/synonyms.htm这是一个答案: 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. Oracle 同义词基本上允许您创建指向存在于其他地方的对象的指针。 You need Oracle synonyms because when you are logged into Oracle, it looks for all objects you are querying in your schema (account).您需要 Oracle 同义词,因为当您登录到 Oracle 时,它​​会在您的架构(帐户)中查找您正在查询的所有对象。 If they are not there, it will give you an error telling you that they do not exist.如果它们不存在,它会给您一个错误,告诉您它们不存在。

I am using Oracle Database and i had same problem.我正在使用 Oracle 数据库,但遇到了同样的问题。 Eventually i found ORACLE DB is converting all the metadata (table/sp/view/trigger) in upper case.最终我发现 ORACLE DB 正在以大写形式转换所有元数据(表/sp/视图/触发器)。

And i was trying how i wrote table name (myTempTable) in sql whereas it expect how it store table name in databsae (MYTEMPTABLE).我正在尝试如何在 sql 中写入表名(myTempTable),而它期望它如何在数据库中存储表名(MYTEMPTABLE)。 Also same applicable on column name.也同样适用于列名。

It is quite common problem with developer whoever used sql and now jumped into ORACLE DB.对于使用 sql 并现在跳入 ORACLE DB 的开发人员来说,这是一个很常见的问题。

in my case when i used asp.net core app i had a mistake in my sql query.就我而言,当我使用 asp.net core 应用程序时,我的 sql 查询出错了。 If your database contains many schemas, you have to write schema_name before table_name, like: Select * from SCHEMA_NAME.TABLE_NAME... i hope it will helpful.如果你的数据库包含很多模式,你必须在 table_name 之前写 schema_name,比如:Select * from SCHEMA_NAME.TABLE_NAME...我希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM