Oracle 同义词

CREATE SYNONYM

Use the CREATE SYNONYM statement to create a synonym, which is an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym.

synonyms are not a substitute for privileges on database objects. Appropriate privileges must be granted to a user before the user can use the synonym.

Prerequisites

To create a private synonym in your own schema, you must have the CREATE SYNONYM system privilege.

To create a private synonym in another user's schema, you must have the CREATE ANY SYNONYM system privilege.

To create a PUBLIC synonym, you must have the CREATE PUBLIC SYNONYM system privilege.

PUBLIC

Specify PUBLIC to create a public synonym. Public synonyms are accessible to all users. However each user must have appropriate privileges on the underlying

object in order to use the synonym.最好不要创建公共同义词

When resolving references to an object, Oracle Database uses a public synonym only if the object is not prefaced by a schema and is not followed by a database link.

If you omit this clause, then the synonym is private and is accessible only within its schema. A private synonym name must be unique in its schema.

Notes on Public Synonyms The following notes apply to public synonyms:

  • If you create a public synonym and it subsequently has dependent tables or dependent valid user-defined object types, then you cannot create another database object of the same name as the synonym in the same schema as the dependent objects.
  • Take care not to create a public synonym with the same name as an existing schema. If you do so, then all PL/SQL units that use that name will be invalidated.

Examples

CREATE SYNONYM: Examples To define the synonym offices for the table locations in the schema hr, issue the following statement:

CREATE SYNONYM offices
   FOR hr.locations;

 

To create a PUBLIC synonym for the employees table in the schema hr on the remote database, you could issue the following statement:

CREATE PUBLIC SYNONYM emp_table
   FOR hr.employees@remote.us.oracle.com;

 

A synonym may have the same name as the underlying object, provided the underlying object is contained in another schema.

Oracle Database Resolution of Synonyms: Example Oracle Database attempts to resolve references to objects at the schema level before resolving them at the PUBLIC

 synonym level. For example, the schemas oe and sh both contain tables named customers. In the next example, user SYSTEM creates a PUBLICsynonym named customers for oe.customers:

CREATE PUBLIC SYNONYM customers FOR oe.customers;

 

If the user sh then issues the following statement, then the database returns the count of rows from sh.customers:

SELECT COUNT(*) FROM customers;

 

To retrieve the count of rows from oe.customers, the user sh must preface customers with the schema name. (The user sh must have select permission onoe.customers as well.)

SELECT COUNT(*) FROM oe.customers;

 

If the user hr's schema does not contain an object named customers, and if hr has select permission on oe.customers, then hr can access the customers table inoe's schema by using the public synonym customers:

SELECT COUNT(*) FROM customers;

 

查询信息

user/all/dba_synonyms

 

 

posted @ 2018-12-04 18:00  春困秋乏夏打盹  阅读(214)  评论(0编辑  收藏  举报