当前位置: DBARoad > Unix | Shell > 文章正文

对多用户批量授权

                    作者 :OoNiceDream【转载时请务必以超链接形式标明文章原始出处和作者信息】
                    链接:http://www.dbaroad.me/archives/2008/11/grant-users-privilege.html

建立一批只具有select权限的用户,在原用户后加上后缀”_SELECT”,要求具有与原用户相同的所有的对表的select权限,及SELECT原用户下所有的表
其实也就是查询:

dba_tab_privs where grantee='原用户' and privilege='SELECT'
加上
dba_tables where owner='原用户'

就可以了。因为用户太多,一一查询授权,比较费时,写了个脚本,批量授权:

export ORACLE_SID=
export ORACLE_HOME=   
for user  in XG JF MIG_XZ ZG MIG_ZS MIG_JH ZC SJ ZY CP ZK QD KT BILLOWE
do
export us1=$user
export us2=${user}_SELECT
sqlplus -s /nolog< <EOF
conn / as sysdba
col user1 new_value user1 
col user2 new_value user2
select '$us1' user1 from dual;
select '$us2' user2 from dual;
set head off
set feedback off
set verify off
spool grant_$us2.sql
select 'grant select on '||owner||'.'||'"'||table_name||'"'||' to &user2;' 
from dba_tables where owner='&user1';
select 'grant select on '||owner||'.'||'"'||table_name||'"'||' to &user2;' 
from dba_tab_privs where grantee='&user1' and privilege='SELECT';
spool off
@grant_$us2.sql
exit
EOF
done
exit

— The End —

关键字:
喜欢DBARoad的文章,那就通过 RSS Feed 功能订阅阅读吧!

我要评论

*

* 绝不会泄露


  • 订阅


      抓虾
      google reader
      my yahoo
      bloglines
      鲜果
      有道

站内搜索



返回首页 | 关于我 | 联系我 | 广告合作 | 网站地图 | 友情链接 | 版权声明 |