oracle database link的管理和使用注意事项

本文介绍了如何使用SQL语句在Oracle数据库中创建和删除数据库链接(databaselink)。通过这些链接可以在不同的Oracle数据库间进行数据访问。文章还提到了与数据库链接相关的视图以及使用后关闭链接的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、创建database link

Use the CREATE DATABASE LINK statement to create a database link. Adatabase link is a schema object in one database that enables you to access objects on another database.

After you have created a database link, you can use it to refer to tables and views on the other database. In SQL statements, you can refer to a table or view on the other database by appending@dblink to the table or view name. You can query a table or view on the other database with theSELECT statement. You can also access remote tables and views using anyINSERT, UPDATE, DELETE, or LOCKTABLE statement.

To create a private database link, you must have the CREATE DATABASE LINK system privilege. To create a public database link, you must have theCREATE PUBLIC DATABASE LINK system privilege.

Oracle Net must be installed on both the local and remote Oracle databases.

Syntax :

下面是一些关键字的说明。

PUBLIC

Specify PUBLIC to create a public database link available to all users. If you omit this clause, the database link is private and is available only to you.

dblink

Specify the complete or partial name of the database link. If you specify only the database name, then Oracle Database implicitly appends the database domain of the local database.

Use only ASCII characters for dblink. Multibyte characters are not supported. The database link name is case insensitive and is stored in uppercase ASCII characters. If you specify the database name as a quoted identifier, then the quotation marks are silently ignored.

If the value of the GLOBAL_NAMES initialization parameter isTRUE, then the database link must have the same name as the database to which it connects. If the value ofGLOBAL_NAMES is FALSE, and if you have changed the global name of the database, then you can specify the global name.

The maximum number of database links that can be open in one session or one instance of a Real Application Clusters configuration depends on the value of the OPEN_LINKS and OPEN_LINKS_PER_INSTANCE initialization parameters.

NOTE:

You cannot create a database link in another user's schema, and you cannot qualifydblink with the name of a schema. Periods are permitted in names of database links, so Oracle Database interprets the entire name, such asralph.linktosales, as the name of a database link in your schema rather than as a database link namedlinktosales in the schema ralph.)

CONNECT TO

The CONNECT TO clause lets you enable a connection to the remote database.

user IDENTIFIED BY password

Specify the user name and password used to connect to the remote database using afixed user database link.

USING 'connect string'

Specify the service name of a remote database. If you specify only the database name, then Oracle Database implicitly appends the database domain to the connect string to create a complete service name. Therefore, if the database domain of the remote database is different from that of the current database, then you must specify the complete service name.

2、删除database link

 Use the DROP DATABASE LINK statement to remove a database link from the database.

To drop a PUBLIC database link, you must have the DROP PUBLIC DATABASE LINK system privilege.

Syntax :

下面是一些关键字的说明。

PUBLIC

You must specify PUBLIC to drop a PUBLIC database link.

dblink

Specify the name of the database link to be dropped.

NOTE:

You cannot drop a database link in another user's schema, and you cannot qualify dblink with the name of a schema, because periods are permitted in names of database links. Therefore, Oracle Database interprets the entire name, such as ralph.linktosales, as the name of a database link in your schema rather than as a database link named linktosales in the schema ralph.

3、与database link相关的视图

USER_DB_LINKS describes the database links owned by the current user.

ALL_DB_LINKS describes the database links accessible to the current user.

DBA_DB_LINKS describes all database links in the database.

V$DBLINK describes all database links opened by the session.The database links with IN_TRANSACTION=YES must be committed or rolled back before being closed.

4、database link用完之后,要记得及时关闭

When you issue a statement that uses a database link, Oracle Database creates a session for you on the remote database using that link.

The connection remains open until you end your local session or until the number of opened database links for your session exceeds the value of the initialization parameter OPEN_LINKS.

you can use the following statement to close the link explicitly if you do not plan to use it again in your session.

sql> ALTER SESSION CLOSE DATABASE LINK db_link;

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沉淀期待未来9527

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值