我使用 SQL Developer,在创建用户并使用所有所需权限与该用户建立另一个连接后,使用系统用户与数据库建立了连接。
但是当我尝试继续以下操作时,出现 SQL 错误
ORA-00942表或视图不存在:
INSERT INTO customer (c_id,name,surname) VALUES ('1','Micheal','Jackson')
因为这篇文章是搜索“ORA-00942:表或视图不存在插入”时在 stackoverflow 上找到的最上面的一篇,所以我想提一下导致此错误的另一个可能原因(至少在 Oracle 12c 中):表使用序列设置默认值,并且执行插入查询的用户对序列没有选择权限。这是我的问题,我花了不必要的很长时间才弄清楚。
要重现该问题,请执行以下 SQL: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;
然后,执行此插入语句user2
:
insert into user1.customer (name,surname) values ('michael','jackson');
结果将是“ORA-00942:表或视图不存在”,即使user2
具有插入和选择权限user1.customer
表并正确地使用架构所有者名称作为表前缀。为了避免该问题,您必须授予序列的选择权限:
grant select on seq_customer_id to user2;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)