A database link is a path through which a remote user in another database can connect to any other database. Once created the database link exists as an object in the user schema.
The following link types are supported:
- Private database link – belongs to a specific schema of a database. Only the owner of a private database link can use it.
- Public database link – all users in the database can use it.
- Global database link – defined in an OID or Oracle Names Server. Anyone on the network can use it.
Syntax to create DB Link
CREATE DATABASE LINK remotedb CONNECT TO &user_name IDENTIFIED BY &password USING ‘tns_conn_str’;
Example
Here is an example to connect FUT instance from DEV instance. DB Link should be created in DEV to access FUT from DEV.
CREATE DATABASE LINK dev2fut CONNECT TO apps IDENTIFIED BY apps123 USING
'(DESCRIPTION =
(ADDRESS=(PROTOCOL=tcp)(HOST=fut.oracleappsdna.com)(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=oadna-fut)
(INSTANCE_NAME=OADNA-FUT)))';
Usage of DB Link
Below is an example to access EMP table in FUT instance from DEV instance using above created DB link
SELECT * FROM emp@dev2fut;
Below DB Views are helpful for working with DB links in Oracle:
- DBA_DB_LINKS – All DB links defined in the database
- ALL_DB_LINKS – All DB links the current user has access to
- USER_DB_LINKS – All DB links owned by current user