oracle下的synonyms,Oracle下Synonyms的使用

Synonyms

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

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 PUBLIC synonym 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 on oe.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 in oe 's schema by using the public synonym customers :

SELECT COUNT(*) FROM customers;

Example2

问题描述:

有两个oralce数据库用户:lyweb@martdb1和lylocal@martdb1

lylocal@martdb1下的表ft_mid_user_daily

在lyweb@martdb1下要用该表

想在lyweb@martdb1下进行如下操作:

select * from ft_mid_user_daily

问题解答:

1.在lylocal@martdb1下进行赋权限:

grant select on ft_mid_user_daily to lyweb;

2.在lyweb@martdb1下进行如下操作:

create or replace synonym ft_mid_user_daily for lylocal.ft_mid_user_daily;

需要注意的一点:

在 lyweb@martdb1中不能包含有表ft_mid_user_daily,虽然create or replace synonym 语句可以执行,但是执行select * from ft_mid_user_daily(本意为想读lylocal@martdb1下的ft_mid_user_daily中的内容),但显示的还是 lyweb@martdb1下的表ft_mid_user_daily内容,需要先把lyweb@martdb1下的表 ft_mid_user_daily删除掉,重新建立synonym即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值