oracle 为托管在不同服务器中的数据库中的表创建同义词

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11662047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:21:48  来源:igfitidea点击:

create synonym for table in a database hosted in a different server

oraclesynonymnetezza

提问by chemicalkt

In oracle, if the other database is within the same server, I did the following to create a synonym

在oracle中,如果其他数据库在同一台服务器内,我做了以下创建同义词

CREATE SYNONYM synonymName FOR databaseName.schema.table;

What should I do to create a synonym for tables in a database hosted in a different server so that I could provide the server connection credentials.

我应该怎么做才能为托管在不同服务器中的数据库中的表创建同义词,以便我可以提供服务器连接凭据。

I need this for both oracle and netezza.

我对 oracle 和 netezza 都需要这个。

Edit: While trying(for Oracle) by taking reference of the answer below, I got a syntax error when the remote link contains ip address or a '-' in the link name. eg.

编辑:通过参考下面的答案尝试(针对 Oracle)时,当远程链接包含 ip 地址或链接名称中的“-”时,出现语法错误。例如。

CREATE PUBLIC DATABASE LINK abc-def.xyz.com CONNECT TO user IDENTIFIED BY pw USING 'databaseName';

回答by DCookie

For Oracle, you would create a database link to the remote database:

对于 Oracle,您将创建一个到远程数据库的数据库链接:

CREATE PUBLIC DATABASE LINK rmt CONNECT TO user IDENTIFIED BY pw USING 'remotedb';

Then create the synonym:

然后创建同义词:

CREATE SYNONYM syn FOR schema.table@rmt;

Then simply SELECT x,y,z FROM syn;

然后简单地 SELECT x,y,z FROM syn;

Not sure about netezza.

不确定 netezza。

EDIT:

编辑:

You cannot use a "-" character in a database link name.

不能在数据库链接名称中使用“-”字符。

If you choose to use an IP address in a link name, then you must surround the link name in double quotes. Not sure why you'd want to do this anyway - what if the IP address of your remote database changes? To me, the DB link name should be a mnemonic for the remote database. An IP address tells me little.

如果您选择在链接名称中使用 IP 地址,则必须用双引号将链接名称括起来。不确定您为什么要这样做 - 如果远程数据库的 IP 地址发生变化怎么办?对我来说,数据库链接名称应该是远程数据库的助记符。IP 地址告诉我的信息很少。

回答by Ravi Parekh

In Addition to @DCookie

除了@DCookie

If you want to create synonym of remote DB.

如果要创建远程数据库的同义词。

CREATE PUBLIC DATABASE LINK rmt CONNECT TO user IDENTIFIED BY pw USING 
'HOST_NAME:PORT/SERVICE_NAME_SID'