Oracle授权A用户查询B用户的所有表
需求:
新建的用户userA,要授权给他访问用户scott的所有表
有三种两方法:
1)
SQL> conn / as sysdba;
SQL> grant select any table on userA
这种方法的缺点是授予的权限过大,userA不仅可以访问scott下的所有表,也可以访问其他用户包括sys,system下的所有表。
2)
SQL> conn scott/tiger;
SQL> select ‘GRANT SELECT ON’ || table_name || ‘to userA;’ from user_tables
得到的结果如下
grant select on emp to userA;
grant select on dept to userA;
grant select on bonus to userA;
grant select on loc to userA;
再把上面得到的结果逐一执行一遍:
SQL> grant select on emp to userA;
SQL> grant select on dept to userA;
SQL> grant select on bonus to userA;
SQL> grant select on loc to userA;
这种方法的缺点是要执行比较多的语句,如果有100个表,就得执行100个grant语句;
另外scott新建的表不在被授权的范围内,新建的表要想被userA访