How to create a database link in Oracle

Oracle

A database link creates a connection between a local database and a remote database. You might want to create a database link, for instance, if you want the data in a remote database updated when the local database is updated. Hereís how to do this:

  1. Create the entry for the remote database in your tnsnames.ora eg:

REMOTE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.20.4.220)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = REMOTE)
)
)

  1. Now go to SQL*PLUS and create the db link

CREATE DATABASE LINK other_db CONNECT TO scott IDENTIFIED BY tiger USING ëtns_aliasí;

Give the DB link a good name. In my example weíll call it ëother_dbí

You can test the database link with a simple query like the following:

SELECT sysdate FROM [email protected]_db;

Select * FROM [email protected]_db where rownum<100;?