您的位置:首页 > 其它

创建一个只有select 权限的用户

2010-01-28 19:46 429 查看
添加用户NewA对用户OldB只有select 的权限步骤:

1. 新建用户

SQL> create user newA identified by"admin";

用户已创建。

SQL> grant connect,resource to newA;

授权成功。

SQL>

2.用OldB(如:scott)进行连接,用拼字符串的方式来将scott用户的select权限赋予新用户newA,并执行拼成的select串。

SQL> conn scott/admin;

已连接。

SQL> Select 'grant select onscott.'||table_name||' to newA;' from user_tables;

'GRANTSELECTONSCOTT.'||TABLE_NAME||'TONEWA;'

-------------------------------------------------------------

grant select on scott.DEPT to newA;

grant select on scott.EMP to newA;

grant select on scott.BONUS to newA;

grant select on scott.SALGRADE to newA;

SQL> grant select on scott.DEPT to newA;

授权成功。

SQL> grant select on scott.EMP to newA;

授权成功。

SQL> grant select on scott.BONUS tonewA;

授权成功。

SQL> grant select on scott.SALGRADE tonewA;

授权成功。

SQL>

或者通过命令:

SQL>grant select any table to newuser;

3. 创建同义词:拼创建同名词串,要赋予新用户create synonym的权限。

SQL> conn / as sysdba

已连接。

SQL> grant create synonym to newA;

授权成功。

SQL>

SQL> conn scott/admin;

已连接。

SQL> select 'create synonym '||table_name ||' for scott.'|| table_name ||';' fr

om user_tables;

'CREATESYNONYM'||TABLE_NAME||'FORSCOTT.'||TABLE_NAME||';'

---------------------------------------------------------------------------

create synonym DEPT for scott.DEPT;

create synonym EMP for scott.EMP;

create synonym BONUS for scott.BONUS;

create synonym SALGRADE for scott.SALGRADE;

4. 用新用户连接,执行上面创建的同名词串,然后就可以查询scott用户的所有表了,这样就跟查询自己的表一样。在实际工作中。给与其他用户对自己表的查询权限是很有用的。

SQL> conn newa/admin;

已连接。

SQL> create synonym DEPT for scott.DEPT;

同义词已创建。

SQL> create synonym EMP for scott.EMP;

同义词已创建。

SQL> create synonym BONUS forscott.BONUS;

同义词已创建。

SQL> create synonym SALGRADE forscott.SALGRADE;

同义词已创建。

SQL>

SQL> conn newa/admin;

已连接。

SQL> select * from dept;

DEPTNO DNAME LOC

---------- -------------- -------------

10 ACCOUNTING NEW YORK

20 RESEARCH DALLAS

30 SALES CHICAGO

40 OPERATIONS BOSTON

SQL> drop dept;

drop dept

*

第 1 行出现错误:

ORA-00950: 无效DROP 选项

操作结束,现在新用户newA已经对scott用户的所有表都具有了查询的权限。

-------------------------------------------------------------------------------------------------------

Blog: http://blog.csdn.net/tianlesoftware
Weibo: http://weibo.com/tianlesoftware
Email: dvd.dba@gmail.com

DBA1 群:62697716(满); DBA2 群:62697977(满) DBA3 群:62697850(满)

DBA 超级群:63306533(满); DBA4 群: 83829929(满) DBA5群: 142216823(满)

DBA6 群:158654907(满) 聊天 群:40132017(满) 聊天2群:69087192(满)

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: