Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View loses its grants when modifying

Is it normal for an oracle view to loose all its grants when modifying the source SQL? I am using SQL Developer if that has anything to do with it.

like image 404
Lock Avatar asked Nov 22 '25 07:11

Lock


1 Answers

First of all, you don't have "grants" - "grant" is an operation. You have "roles" and "privileges".

Second, views have neither roles nor privileges themselves - schemas do have. Basically, a self-descriptive command is: grant select on view_1 to schema_1.

Third, schemas do not lose their privileges if you create or replace your view. Here's a quick sample:

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                         

However, it is quite possible that SQL developer invokes drop view first instead of create or replace. In this case, your privileges are automatically removed.

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                                                                                                                
like image 182
Kirill Leontev Avatar answered Nov 24 '25 21:11

Kirill Leontev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!