Ser*_*nez 15 select grant oracle11g
我有3个表table1,table2,table3.我想将这些表授予(例如选择)给用户user1.
我知道我可以批准:
grant select on table1 to user1;
grant select on table2 to user1;
grant select on table3 to user1;
Run Code Online (Sandbox Code Playgroud)
我可以仅使用1个查询将3个表授予user1吗?
谢谢
小智 8
您可以使用动态查询来执行此操作,只需在pl-sql或sqlplus中运行以下脚本:
select 'grant select on user_name_owner.'||table_name|| 'to user_name1 ;' from dba_tables t where t.owner='user_name_owner'
Run Code Online (Sandbox Code Playgroud)
然后执行结果.
我的建议是......在oracle中创建角色
create role <role_name>;
Run Code Online (Sandbox Code Playgroud)
然后使用分配给该角色的权限
grant select on <table_name> to <role_name>;
Run Code Online (Sandbox Code Playgroud)
然后通过使用该角色将该组权限分配给任何用户
grant <role_name> to <user_name>...;
Run Code Online (Sandbox Code Playgroud)