同义词

同义词:
1 什么是同义词:
同义词就是别名.

2 同义词使用的场合.

xiaohong想访问scott用户的emp表:

1
2
3
4
5
6
1 需要scott用户给xiaohong赋访问emp表的权限:
grant select on emp to xiaohong;
然后使用xiaohong用户登录oracle:
sqlplus xiaohong/xiaohong@oracle;
SQL> select * from scott.emp;
为了在访问scott.emp表的时候不用再使用scott.emp,可以给scott.emp创建同义词;

3 如何创建同义词:

1
2
create synonym 同义词名 for 用户名.表名;
create synonym emp for scott.emp;

如何创建一个新的oracle用户

1
2
3
4
5
6
7
8
使用sys用户创建新的用户和给这个新用户添加权限:
create user 用户名 identified by 密码;
grant connect, resource to 用户名; --给用户添加连接权限,如果一个新用户没有连接权限的话,是无法连接到这个用户的
grant create synonym to 用户名; --给用户添加创建同义词的权限

create user xiaohei identified by xiaohei;
grant connect, resource to xiaohei;
grant create synonym to xiaohei;

4 删除同义词:

1
2
drop synonym 同义词名;
drop synonym emp;

5 查询同义词

1
select synonym_name from user_synonyms;