以下内容整理自Oracle 官方文档

一 概念

A synonym is an alias for any table, view,materialized view, sequence, procedure, function, package, type, Java classschema object, user-defined object type, or another synonym. Because a synonymis simply an alias, it requires no storage other than its definition in thedata dictionary.

Oracle中同义词是任何表、视图、物化视图、序列、存储过程函数、包、类型、JAVA类对象、用户定义类型,或是其他的同义词的别名。由于其只是一个别名,所以除了在

数据字典中的定义不占任何空间。

Synonyms are often used for security andconvenience. For example, they can do the following:

同义词常用于安全和方便。例如,它们可以做:

1. Mask the name and owner of anobject  伪装对象名称和其所有者。

2. Provide location transparency for remoteobjects of a distributed database 为分布式数据库远程对象提供位置透明性

3. Simplify SQL statements for databaseusers 简化数据库用户访问对象SQL语句

4. Enable restricted access similar tospecialized views when exercising fine-grained access control 当行使精细化访问控制时提供类似指定视图的访问限制

You can create both public and privatesynonyms. A public synonym is owned by the special user group named PUBLIC andevery user in a database can access it. A private synonym is in the schema of aspecific user who has control over its availability to others.

你可以创建public和private同义词。public同义词属于PUBLIC组,每个用户都可以访问。private同义词属于对象所有者,只有其显式授权后其他用户才可访问。

Synonyms are very useful in bothdistributed and nondistributed database environments because they hide theidentity of the underlying object, including its location in a distributedsystem. This is advantageous because if the underlying object must be renamedor moved, then only the synonym needs to be redefined. Applications based onthe synonym continue to function without modification.

同义词的优势体现在如果其底层的对象重命名或者转移,那么只需要重定义该同义词。基于该同义词的应用则无需任何修改。

Synonyms can also simplify SQL statementsfor users in a distributed database system. The following example shows how andwhy public synonyms are often created by a database administrator to hide theidentity of a base table and reduce the complexity of SQL statements. Assume thefollowing:

下面举例说明同义词是如何简化用户访问的:

A table called SALES_DATA is in the schemaowned by the user JWARD.

JWARD用户下有一张表 SALES_DATA

The SELECT privilege for the SALES_DATAtable is granted to PUBLIC.

PUBLIC组有SALES_DATA的查询权限

At this point, you have to query the tableSALES_DATA with a SQL statement similar to the following:

此时,你如果查询SALES_DATA表则需以下语句:

SELECT * FROM jward.sales_data;

Notice how you must include both the schemathat contains the table along with the table name to perform the query.

Assume that the database administratorcreates a public synonym with the following SQL statement:

假如数据库管理员创建了一个public 同义词:

CREATE PUBLIC SYNONYM sales FORjward.sales_data;

After the public synonym is created, youcan query the table SALES_DATA with a simple SQL statement:

你的语句将简化为:

SELECT * FROM sales;

Notice that the public synonym SALES hidesthe name of the table SALES_DATA and the name of the schema that contains thetable.

二、CREATE SYNONYM 创建同义词

1、语法结构:

2、前提条件:

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

在自己模式下创建私有同义词需要CREATE SYNONYM权限。

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

在其他用户模式下创建私有同义词需要CREATE ANY SYNONYM权限。

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

创建公有同义词,需要有CREATE PUBLIC SYNONYM权限。

3、示例

sqlplus / as sysdba

CREATE SYNONYM offices

FOR hr.locations;

GRANT SELECT ON hr.locations to SCOTT;

CREATE PUBLIC DATABASE LINK l_hr

CONNECT TO hr IDENTIFIED BY hr

USING 'orcl';

CREATE PUBLIC SYNONYM emp_table

FORHR.employees@l_hr;

GRANT SELECT ON HR.employees to SCOTT;

conn scott/tiger@orcl

SELECT count(*) from sys.offices;

select count(*) from emp_table;

三、DROP SYNONYM  删除同义词

1、语法结构:

2、前提条件:

To drop a private synonym, either the synonym must be in your own schema or you must have the DROP ANY SYNONYM system privilege.

删除私有同义词需要有DROP ANY SYNONYM权限。

To drop a PUBLIC synonym, you must have the DROP PUBLIC SYNONYM system privilege.

删除公有同义词需要有DROP PUBLIC SYNONYM权限。

3、示例

3.1删除public同义词,必须加public关键字:

SYS@orcl>DROP SYNONYM emp_table;

DROPSYNONYM emp_table

*

第 1 行出现错误:

ORA-01434:要删除的专用同义词不存在

SYS@orcl>DROP PUBLIC SYNONYM emp_table;

同义词已删除。

3.2删除private同义词:

DROP SYNONYM offices;

四、Q&A 问答

Q: 可以对同义词做INSERT/UPDATE/DELETE操作吗?

A:

SCOTT@orcl> UPDATE sys.offices t SETt.city='Shanghai' WHERE location_id=1000;

UPDATE sys.offices t SET t.city='Shanghai'WHERE location_id=1000

*

第 1 行出现错误:

ORA-01031: 权限不足

SYS@orcl> grant update on hr.locationsto scott;

授权成功。

SCOTT@orcl> /

已更新 1 行。

SO: 用户对同义词的操作权限都是基于对其底层对象有哪些操作权限。

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

Dylan   Presents.

ORACLE SYNONYM详解的更多相关文章

  1. 创建Oracle synonym 详解

    --创建使用同义词 --同义词就是给表.视图等对象取得别名,用于简化对其的访问 --分为2种: --私有同义词:用户自己创建自己使用的 --公共同义词:dba创建,给其它用户使用的 --为dept_s ...

  2. Oracle 同义词详解(synonym)

    Oracle 同义词详解(synonym) 一.Oracle同义词概念 Oracle 数据库中提供了同义词管理的功能.同义词是数据库方案对象的一个别名,经常用于简化对象访问和提高对象访问的安全性.在使 ...

  3. Oracle数据字典详解

    学习笔记:oracle数据字典详解 --- 本文为TTT学习笔记,首先介绍数据字典及查看方法,然后分类总结各类数据字典的表和视图.然后列出一些附例.   数据字典系统表,保存在system表空间中. ...

  4. Oracle内存详解之 Library cache 库缓冲

    Oracle内存详解之 Library cache 库缓冲 2017年11月09日 11:38:39 阅读数:410更多 个人分类: 体系结构 Library cache是Shared pool的一部 ...

  5. oracle 数据类型详解---日期型(转载)

    oracle 数据类型详解---日期型 oracle数据类型看起来非常简单,但用起来会发现有许多知识点,本文是我对ORACLE日期数据类型的一些整理,都是开发入门资料,与大家分享: 注:由于INTER ...

  6. oracle 序列 详解

    序列: 是oacle提供的用于产生一系列唯一数字的数据库对象. l  自动提供唯一的数值 l  共享对象 l  主要用于提供主键值 l  将序列值装入内存可以提高访问效率 创建序列: 1.  要有创建 ...

  7. oracle checkpoint 详解

    Oracle checkpoint详解 topcheckpoint扫盲 top什么是checkpoint 在数据库系统中,写日志和写数据文件是数据库中IO消耗最大的两种操作,在这两种操作中写数据文件属 ...

  8. oracle rowid 详解

    oracle rowid详解 今天是2013-09-15,存储在数据库中的每一行数据都有一个地址,oracle使用rowid数据类型在存储地址.rowid有如下类别: 1)physical rowid ...

  9. Oracle索引详解

    Oracle索引详解(二) --索引分类   Oracle 提供了大量索引选项.知道在给定条件下使用哪个选项对于一个程序的性能来说非常重要.一个错误的选择可能会引发死锁,并导致数据库性能急剧下降或进程 ...

随机推荐

  1. 怎样从外网访问内网微服务Microservices?

    本地部署了一个微服务,只能在局域网内访问,怎样从外网也能访问到本地的微服务呢?本文将介绍具体的实现步骤. 准备工作 部署并启动微服务程序 默认部署的微服务端口是8088. 实现步骤 下载并解压hole ...

  2. 【视频】使用fiddler开发工具进行新架构页面本地调试

    [视频]使用fiddler开发工具进行新架构页面本地调试,视频没录制好,有些部分比较模糊...

  3. Python实现京东自动登录

    配置好webdriver,用的是Chrome的 import cv2 import time import numpy as np from selenium import webdriver fro ...

  4. Vue中的事件与常见的问题处理

    Vue的事件:获取事件对象$event: 事件冒泡:事件会向上传播 原生js阻止事件冒泡,需要先获取事件对象,再调用stopPropagation()方法: vue事件修饰符stop,例@clik.s ...

  5. java.util.concurrent.RejectedExecutionException: event executor terminated解决方法之一

    INFO | jvm 1 | 2017/03/09 19:45:10 | java.util.concurrent.RejectedExecutionException: event executor ...

  6. Angular 请求数据

    Angular 请求数据 get post 以及 jsonp 请求数据 引入 HttpModule .JsonpModule 普通的 HTTP 调用并不需要用到 JsonpModule,不过稍后我们就 ...

  7. (4运行例子)自己动手,编写神经网络程序,解决Mnist问题,并网络化部署

    ​1.联通ColaB 2.运行最基础mnist例子,并且打印图表结果  # https://pypi.python.org/pypi/pydot#!apt-get -qq install -y gra ...

  8. JAVA基础部分 JDK和JRE以及JVM

    第一部分: 一.dos命令 *快捷查看电脑ip: Win + R进入cmd;输入ipconfig/all查看IPv4:192.168.0.xxx(首选); 基本命令: cd进入目录:d: 直接进入盘符 ...

  9. 2018年12月7日 字符串格式化2 format与函数1

    tp7="i am \033[44;1m %(name)-25.6s\033[0m"%{"name":"sxj2343333"} print ...

  10. 51nod 四级题 汇总

    51Nod-1060-最复杂的数 #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; ...