Jen*_*der 4 oracle privileges create-table sql-grant
我使用SYSTEM用户授予CREATE ANY TABLE用户TEST,但是当我尝试执行时
create table other.dummy ...
我仍然得到ORA-01031: insufficient privileges
Oracle:授予在另一个模式中创建表?声称这应该有效。
我也尝试授予CREATE ANY INDEX因为该表具有 PK,因此包含索引,但这并没有改变任何内容。
GRANT ALL PRIVILEGES做到了这一点,但我更喜欢一些更有限的东西。
实际的CREATE TABLE说法是:
CREATE TABLE OTHER.DUMMY_ENTITY ( 
    ID NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY, 
    NAME VARCHAR2(30) 
)
除此之外我还需要授予哪些特权CREATE ANY TABLE?
当您向特定用户授予权限时CREATE ANY TABLE,该用户将能够在数据库中创建任何表,只要该表的创建与您正在运行的语句兼容。就您而言,您不仅仅是创建一个表。
让我们通过创建具有此类权限的用户,然后尝试在另一个架构中创建表来模拟您的场景。
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Nov 5 10:54:17 2021
Version 19.6.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
SQL> show user
USER is "SYS"
SQL>
SQL> create user test_grant identified by "Oracle_123" ;
User created.
SQL> grant create session, create any table to test_grant ;
Grant succeeded.
SQL> exit
现在,我正在连接以test_grant在架构中创建一个与您相同的表test
sqlplus test_grant/"Oracle_123"
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Nov 5 10:55:28 2021
Version 19.6.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
SQL> create table test.t1_privs ( c1 number generated by default on null as identity primary key , c2 varchar2(1) ) ;
create table test.t1_privs ( c1 number generated by default on null as identity primary key , c2 varchar2(1) )
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> create table test.t2_privs ( c1 number, c2 varchar2(1) ) ;
Table created.
正如您所看到的,我可以在其他模式中创建一张表,但不能在您想要创建的模式中创建。显然,语句中的元素create table需要其他权限,所以让我们分析它们
让我们给用户这些权限
SQL> grant create any index, create any sequence to test_grant ;
Grant succeeded.
再试一次
sqlplus test_grant/"Oracle_123"
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Nov 5 11:06:47 2021
Version 19.6.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Last Successful login time: Fri Nov 05 2021 11:03:31 +01:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
SQL> create table test.t1_privs ( c1 number generated by default on null as identity primary key ,  c2 varchar2(1) ) ;
create table test.t1_privs ( c1 number generated by default on null as identity primary key,  c2 varchar2(1) )
*
ERROR at line 1:
ORA-01031: insufficient privileges
那么,到底发生了什么?
当你在另一个模式中创建一个以列作为标识的表时,你不仅需要 和create any table权限create any sequence,还需要select any sequence权限
SQL> grant select any sequence to test_grant ;
Grant succeeded.
sqlplus test_grant/"Oracle_123"
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Nov 5 11:31:44 2021
Version 19.6.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Last Successful login time: Fri Nov 05 2021 11:29:36 +01:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.6.0.0.0
SQL> create table test.t1_privs ( c1 number generated by default on null as identity primary key, c2 varchar2(1) ) ;
Table created.