Roles are indeed a convenient way to organize permission sets and are also widely used in many systems. However, in Oracle, role privilege should be especially careful when using role permissions, especially during database development. Because the structure such as the Oracle stored procedure has a Removing Effect on Role permissions. [Experiment] // Create an experiment role r_cat_role SQL> Create role r_cat_role; Role created // Grant the system permission select any dictionary to the experiment role. The select any dictionary permission can access most of the metadata views of oracle. SQL> grant select any dictionaryto r_cat_role; Grant succeeded // Create a user SQL> create user mytest identified by mytest; User Created SQL> grant create session to mytest; Grant succeeded SQL> grant r_cat_role to mytest; Grant succeeded SQL> grant create procedure to mytest; Grant succeeded SQL> conn mytest/mytest @ ora11g; Connected to Oracle database11genterpriseedition release11.2.0.1.0 Connected as mytest SQL> select count (*) fromdba_objects; Count (*) ---------- 72282 The dba_objects view is an integral part of the metadata dictionary. After accepting the role permission r_cat_role, The mytest user has the permission to be directly used in SQL. Below we construct the stored procedure as follows: SQL> Create or replace procedure p_test_nc 2 is 3 n_res number; 4 begin 5 select count (*) 6 into n_res 7 from dba_objects; 8 9 dbms_output.put_line (to_char (n_res )); 10 end p_test_nc; 11/ Warning: procedure created with compilation errors SQL> select * From user_errors; Name type sequence line position text attribute ----------------------------------------------------------------------------------------------------- P_test_nc procedure 1 7 8 PL/SQL: ORA-00942: Table or view no error P_test_nc Procedure 2 5 3 PL/SQL: SQL statement ignored Error Compilation error, which looks incredible. Clearly, mytest users have dba_objects view access permissions and can be directly used in SQL statements. This is because the permission to access dba_objects is granted by the role. The Oracle code structure, such as stored procedures, has a feature that allows you to remove the role permissions in a user's three-tier permissions (role, system, and object. |