Synonyms for Oracle
Synonyms are an alias for schema objects such as tables, indexes, and views. As with views, synonyms do not occupy any real storage space, only the description of their definitions in Oracle's data dictionary. When you use synonyms, Oracle translates them into the corresponding object names.
Synonyms in Oracle are divided into the following two categories:
1. Public synonyms
在数据库中所有用户都可以使用
2. Private synonyms
由创建它的用户私人拥有。不过,用户可以控制其他用户是否有权使用自己的同义词。
Create synonyms
The syntax for creating synonyms is as follows:
CREATE [PUBLIC] SYNONYM synonym_name FOR schema_object;
Example 1:
To give the user permission to create synonyms:
GRANT CREATE PUBLIC SYNONYM TO siege;
Then create synonyms:
CREATE PUBLIC SYNONYM public_stu_syn FOR student;
Delete the synonym using the drop statement. To delete a public synonym, you need the appropriate permissions:
GRANT DROP PUBLIC SYNONYM TO siege;
At this point, delete the public synonym:
DROP PUBLIC SYNONYM public_stu_syn;
To view synonyms:
SELECT * FROM user_synonyms WHERE synonym_name=‘PUBLIC_STU_SYN‘
If you create a public synonym, its definition is stored in dba_synonyms, and the query needs to have the relevant permissions.
Synonyms for Oracle