gpt4 book ai didi

sql - View 在修改时失去其授权

转载 作者:行者123 更新时间:2023-12-02 15:38:18 24 4
gpt4 key购买 nike

Oracle View 在修改源 SQL 时丢失所有授权是否正常?如果这与它有任何关系,我正在使用 SQL Developer。

最佳答案

首先,您没有“grants”——“grant”是一个操作。你有“角色”和“特权”。

其次, View 本身既没有角色也没有特权——模式有。基本上,一个 self 描述的命令是:grant select on view_1 to schema_1

第三,如果您创建或替换您的 View ,模式不会失去它们的特权。这是一个快速示例:

11:03:07 @> conn system/sys@oars_sandbox                                                                                                                            
Connected.
11:03:15 SYSTEM@oars_sandbox> create user test1 identified by test1;

User created.

11:03:39 SYSTEM@oars_sandbox> create user test2 identified by test2;

User created.

11:03:48 SYSTEM@oars_sandbox> create view test1.view1 as select * from dual;

View created.

11:04:03 SYSTEM@oars_sandbox> grant select on test1.view1 to test2;

Grant succeeded.

11:04:15 SYSTEM@oars_sandbox> select grantee, owner, table_name, privilege, grantor from dba_tab_privs where grantee = 'TEST2';

GRANTEE OWNER TABLE_NAME PRIVILEGE GRANTOR
------------------------------ ------------------------------ ------------------------------ ---------------------------------------- ------------------------------
TEST2 TEST1 VIEW1 SELECT TEST1

11:05:13 SYSTEM@oars_sandbox> create or replace view test1.view1 as select * from dual;

View created.

11:05:24 SYSTEM@oars_sandbox> select grantee, owner, table_name, privilege, grantor from dba_tab_privs where grantee = 'TEST2';

GRANTEE OWNER TABLE_NAME PRIVILEGE GRANTOR
------------------------------ ------------------------------ ------------------------------ ---------------------------------------- ------------------------------
TEST2 TEST1 VIEW1 SELECT TEST1

但是,SQL 开发人员很有可能先调用drop view,而不是create or replace。在这种情况下,您的权限将被自动删除。

11:05:26 SYSTEM@oars_sandbox> drop view test1.view1;                                                                            

View dropped.

11:10:21 SYSTEM@oars_sandbox> select grantee, owner, table_name, privilege, grantor from dba_tab_privs where grantee = 'TEST2';

no rows selected

11:10:24 SYSTEM@oars_sandbox> create or replace view test1.view1 as select * from dual;

View created.

11:10:26 SYSTEM@oars_sandbox> select grantee, owner, table_name, privilege, grantor from dba_tab_privs where grantee = 'TEST2';

no rows selected

关于sql - View 在修改时失去其授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13131579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com