Wednesday, February 2, 2011

Dynamic SQL grants in Oracle

Dynamically grant roles. You can use / modify this script to create a role and for instance grant the select role to it:

set feedback off
set heading off

create role MY_SELECT;

spool grant_me.sql

SELECT 'GRANT SELECT ON ' ||owner||'.'|| table_name ||'
TO MY_SELECT;'
FROM dba_tables
WHERE owner = 'SOMEowner';

spool off
set feedback on

@grant_me.sql

exit

Dynamically grant for instance select rights of objects or tables:

SELECT 'GRANT SELECT ON ' ||owner||'.'|| table_name || ' to somedude;' FROM dba_tables WHERE owner = 'someowner';

SELECT 'GRANT SELECT ON ' ||owner||'.'|| object_name || ' to somedude;' FROM dba_objects WHERE owner = 'someowner';

No comments:

Post a Comment