尝试在 Oracle SQL 上新创建的用户上创建序列时,获取“用户或角色 '' 不存在”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35623687/
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
Getting a "user or role '' does not exist" when attempting to create a sequence on a newly created user on Oracle SQL
提问by devoured elysium
I've just created a new user on an Oracle SQL database. I think the sequence of commands on SQL+ is was something such as:
我刚刚在 Oracle SQL 数据库上创建了一个新用户。我认为 SQL+ 上的命令序列是这样的:
> create user testuser identified by mypassword;
> grant all privileges to testuser identified by mypassword;
I then connected to that user through SQL Developer and attempted to run the following code:
然后我通过 SQL Developer 连接到该用户并尝试运行以下代码:
CREATE SEQUENCE "ABC"."DEF_SEQ" MINVALUE 10 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 250 CACHE 20 NOORDER NOCYCLE ;
but I get a threatening
但我收到了威胁
Error at Command Line : 1 Column : 18
Error report -
SQL Error: ORA-01917: user or role '' does not exist
01917. 00000 - "user or role '%s' does not exist"
*Cause: There is not a user or role by that name.
*Action: Re-specify the name.
If I attempt to run a CREATE TABLE
everything seems alright, though:
但是,如果我尝试运行CREATE TABLE
一切似乎没问题:
CREATE TABLE abc(my_id int primary key);
What am I doing wrong? Thanks
我究竟做错了什么?谢谢
回答by Alex Poole
The CREATE SEQUENCE "ABC"."DEF_SEQ"
statement you are using will try to create a sequence called DEF_SEQ
in schema ABC
. You created user/schema TESTUSER
, not ABC
.
CREATE SEQUENCE "ABC"."DEF_SEQ"
您正在使用的语句将尝试创建一个DEF_SEQ
在 schema 中调用的序列ABC
。您创建了 user/schema TESTUSER
,而不是ABC
.
To create it under your actual user you can do:
要在您的实际用户下创建它,您可以执行以下操作:
CREATE SEQUENCE "TESTUSER"."DEF_SEQ" ...
but the schema prefix is only needed if you're logged in as a different user with enough privileges, such as SYS, and you shouldn't generally be doing anything under that account. If you're connected as testuser
you don't need the prefix, just:
但是,仅当您以具有足够权限的其他用户身份(例如 SYS)登录时才需要架构前缀,并且您通常不应在该帐户下执行任何操作。如果您因为testuser
不需要前缀而连接,只需:
CREATE SEQUENCE "DEF_SEQ" ...
It looks like you might be trying to create a sequence under the tableABC
. That isn't how sequences work; they are independent objects, not tied to any table. The same sequence can be used to generate the primary keys for multiple tables, for example.
看起来您可能正在尝试在表下创建一个序列ABC
。这不是序列的工作方式;它们是独立的对象,不绑定到任何表。例如,相同的序列可用于为多个表生成主键。
If you want a sequence that auto-generates primary key values for table ABC
then you need a trigger that sets the key column from the sequence, e.g. in 11g:
如果您想要一个自动为表生成主键值的序列,ABC
那么您需要一个触发器来设置序列中的键列,例如在 11g 中:
create trigger abc_id_trig
before insert on abc
for each row
begin
:new.my_id := def_seq.nextval;
end;
/
From 12c you can hide that with the identity
clause.
从12C可以隐藏与该identity
条款。
回答by Maninder
Please execute this query to sys user
请对 sys 用户执行此查询
alter pluggable database orcl open;
更改可插拔数据库 orcl 打开;
orcl is service|SID name
orcl 是服务|SID 名称
It is working on my side
它在我这边工作