Synonyms 同义词

来源:互联网 发布:和平网络电视不能用 编辑:程序博客网 时间:2024/04/28 17:55

About Synonyms

A synonym is an alias for a schema object. Synonyms can provide a level of security 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.public synonym is owned by the special user group named PUBLIC and is accessible to every user in a database.private synonym is contained in the schema of a specific user and available only to the user and the user's grantees.

Creating Synonyms

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

Create a synonym using the CREATE SYNONYM statement. The underlying schema object need not exist, nor do you need privileges to access the object. The following statement creates a public synonym named public_emp on the emp table contained in the schema of jward:

CREATE PUBLIC SYNONYM public_emp FOR jward.emp

When you create a synonym for a remote procedure or function, you must qualify the remote object with its schema name. Alternatively, you can create a local public synonym on the database where the remote object resides, in which case the database link must be included in all subsequent calls to the procedure or function.


Using Synonyms in DML Statements

You can successfully use any private synonym contained in your schema or any public synonym, assuming that you have the necessary privileges to access the underlying object, either explicitly, from an enabled role, or from PUBLIC. You can also reference any private synonym contained in another schema if you have been granted the necessary object privileges for the private synonym.

You can only reference another user's synonym using the object privileges that you have been granted. For example, if you have the SELECT privilege for thejward.emp synonym, then you can query the jward.emp synonym, but you cannot insert rows using the jward.emp synonym.

A synonym can be referenced in a DML statement the same way that the underlying object of the synonym can be referenced. For example, if a synonym named emp refers to a table or view, then the following statement is valid:

INSERT INTO emp (empno, ename, job)    VALUES (emp_sequence.NEXTVAL, 'SMITH', 'CLERK');

If the synonym named fire_emp refers to a standalone procedure or package procedure, then you could execute it with the command

EXECUTE Fire_emp(7344);

Dropping Synonyms

You can drop any private synonym in your own schema. To drop a private synonym in another user's schema, you must have the DROP ANY SYNONYM system privilege. To drop a public synonym, you must have the DROP PUBLIC SYNONYM system privilege.

Drop a synonym that is no longer required using DROP SYNONYM statement. To drop a private synonym, omit the PUBLIC keyword. To drop a public synonym, include the PUBLIC keyword.

For example, the following statement drops the private synonym named emp:

DROP SYNONYM emp;

The following statement drops the public synonym named public_emp:

DROP PUBLIC SYNONYM public_emp;

When you drop a synonym, its definition is removed from the data dictionary. All objects that reference a dropped synonym remain. However, they become invalid (not usable). For more information about how dropping synonyms can affect other schema objects, see "Managing Object Dependencies".

See Also:

Oracle Database SQL Reference for syntax and additional information about the DROP SYNONYM statement

Viewing Information About Views, Synonyms, and Sequences

The following views display information about views, synonyms, and sequences:

ViewDescriptionDBA_VIEWS

ALL_VIEWS

USER_VIEWS

DBA view describes all views in the database. ALL view is restricted to views accessible to the current user. USER view is restricted to views owned by the current user.DBA_SYNONYMS

ALL_SYNONYMS

USER_SYNONYMS

These views describe synonyms.DBA_SEQUENCES

ALL_SEQUENCES

USER_SEQUENCES

These views describe sequences.DBA_UPDATABLE_COLUMNS

ALL_UPDATABLE_COLUMNS

USER_UPDATABLE_COLUMNS

These views describe all columns in join views that are updatable.


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果手机微信听不到语音怎么办 电信怎么办腾讯频看电视不要流量 孩子做事效率低怎么办教案 孩子做事效率低怎么办读后感 做事效率低总是焦虑怎么办 红米手机黑屏打不开怎么办 手机萤石云视频下载打不开怎么办 oppo打开网页视频慢怎么办? 晒课显示待提交怎么办 华为手机无法访问移动网络怎么办 晒课上传课堂实录太大怎么办 手机酷狗音乐下载要钱怎么办 手机酷狗下载要钱怎么办 酷我音乐没有声音怎么办 手机酷我音乐没有声音怎么办 酷我音乐歌曲下载收费怎么办 网易云下载超过每日上限怎么办 全民k歌领不了花怎么办 安卓全民k歌延迟怎么办 全民k歌唱歌延迟怎么办 全民k歌耳机延迟怎么办 word文档打开是乱码怎么办 全民k歌不能录音怎么办 全民k歌登录不上怎么办 平果手机迅雷闪退怎么办 电脑打开央视影音死机怎么办 先锋影音二级网页打不开怎么办 手机qq音乐登录失效怎么办 酷狗账号忘记了怎么办 手机qq音乐听不了歌怎么办 第一试用网密码忘了怎么办 玩h1z1画面卡顿怎么办 uu跑腿抢不到单怎么办 比特币加密忘了怎么办 路虎发现cd卡死怎么办 苹果手机帐号被锁定怎么办 苹果手机帐号锁定了怎么办 微博帐号被锁定怎么办 微博显示帐号被锁定怎么办 uc屏蔽了一个网站怎么办 uu跑腿送货遇到不方便收货怎么办