This tutorial uses examples to illustrate how to create and delete synonyms (synonym) in Oracle data.
Concept
Synonyms refer to database objects (database objects such as tables, views, sequences, stored procedures, and so on) that are referenced by another name. Like what:
Creating a synonym can exclude the restriction of an object's name.
If your database has multiple users, user_a to access User_b TABLE1, you can only use User_b.table1
Build a synonym ABC point to USER_B.TABLE1, then you can select * from ABC, and the public synonym will appear directly in front of all users, development is not much more convenient
Create synonyms
Grammar:
CREATE [OR REPLACE] [public] synonym [schema.] Synonym_name for [schema.] object_name [@dblink];
Syntax Description:
OR REPLACE: Allows you to recreate (if the synonym already exists) without using drop.
Public: The synonym created is a synonym for the global, and can be used by all database users.
Schema: The schema of the object in which the synonym is to be created, or, if omitted, the default Application object under the current schema.
object_name: The object to create a synonym for, it can be of the following types:
- TABLE
- VIEW
- SEQUENCE
- STORED PROCEDURE
- FUNCTION
- Package
- Materialized VIEW
- JAVA CLASS SCHEMA OBJECT
- user-defined OBJECT
- Synonym
Example:
CREATE public synonym suppliers for app.suppliers;
The synonym created in the example is named suppliers, so that users under other schemas can use the synonym to use the Suppliers table under the app without having to add the app. For example:
SELECT *from Suppliers;
Delete Synonyms
Grammar
DROP [public] synonym [schema.] synonym_name [Force];
Description:
Public: Allow deletion of public synonyms, if the public keyword is used, you can omit the schema.
Force: Used to forcibly delete a synonym, even if it has other dependencies in the database.
Example:
DROP public synonym suppliers;
Synonyms for Oracle database (synonym) use