Oracle Synonym --- fell embarrassedly -_-!!

Posted by Vincent on November 28, 2007

I feel very embarrassedly, when I konw the mean of the Oracle Synonym. Because I confused by the table which not contain in our DB, bu I can select/insert/update the data in the table. Then I found the table in another db. I really confused by that. This table used a synonym for table by dblink.

This is what I found in the Web.

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

问题描述:
有两个oralce数据库
SID分别为 A B
A中a用户下含有表objects
B中含有b用户
使在B中用b用户登录后执行
select * from objects
能显示出A中a.objects的全部内容

问题解答:
用b用户登录到B中,执行:
create public synonym objects for a.objects@A
此时执行select * from objects 就能显示出a.objects的全部内容

需要注意的一点:
B中不能含有table b.objects否则语句可以执行,但是执行select操作时显示的仍然为b.objects的内容,需要先把b.objects删除掉,重新建立synonym即可。

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

A synonym is an alias for a schema object. Synonyms can provide a level of ecurity by masking the name and owner of an object and by providing location transparency for remote objects of a distributed database. Also, they are convenient to use and reduce the complexity of SQL statements for database users.
Synonyms allow underlying objects to be renamed or moved, where only the synonym needs to be redefined and applications based on the synonym continue to function without modification.
You can create both public and private synonyms. A public synonym is owned by the special user group named PUBLIC and is accessible to every user in a database.
A private synonym is contained in the schema of a specific user and available only
to the user and the user’s grantees.


This work is licensed under a CC A-S 4.0 International License.