1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
DECLARE
TYPE cur_typ IS REF CURSOR;
c cur_typ;
query_tables VARCHAR2(200) :='select distinct owner || ''.'' || table_name from dba_tab_privs where grantee=:ROLE';
query_roles VARCHAR2(200) := 'select GRANTED_ROLE from dba_role_privs where grantee=:ROLE';
role_name VARCHAR2(40);
table_name VARCHAR2(40);
granted_role VARCHAR2(40);
TYPE TYPE_TAB IS VARRAY (20) OF VARCHAR2(40);
TAB TYPE_TAB := TYPE_TAB('ROLE1','ROLE2');
BEGIN
-- For each ROLE defined in TAB --
FOR i IN TAB.FIRST..TAB.LAST
LOOP
role_name:=TAB(i);
-- Get TABLE names from the current ROLE --
OPEN c FOR query_tables USING role_name;
LOOP
FETCH c INTO table_name;
EXIT WHEN c%NOTFOUND;
-- Revoke the current TABLE from the current ROLE --
dbms_output.PUT_LINE(table_name);
--EXECUTE IMMEDIATE 'revoke ALL PRIVILEGES on ' || table_name || ' from ' || role_name;
END LOOP;
CLOSE c;
-- END Get TABLE names from the current ROLE --
-- Get ROLE names from the current ROLE --
OPEN c FOR query_roles USING role_name;
LOOP
FETCH c INTO granted_role;
EXIT WHEN c%NOTFOUND;
-- Revoke the current granted ROLE from the ROLE --
dbms_output.PUT_LINE(granted_role);
--EXECUTE IMMEDIATE 'revoke '|| granted_role || ' from ' || role_name;
END LOOP;
CLOSE c;
-- END GetROLE names from the current ROLE --
END LOOP;
-- END For each ROLE defined in TAB --
END;
/ |
Partager