Untitled Document
Untitled Document
Once you create a database link, you can access the tables or views from the remote
database using the following pattern:
When accessing a remote table or view over the database link, the Oracle database
is acting as an Oracle client.
FOR remote_table@database_link;
And this query uses the synonym instead of the remote table name with the
database link:
Private database links are visible to the owners while public database links are
visible to all users in the database. For this reason, public database links may pose
some potential security risks.
To create a private database link, you use the CREATE DATABASE LINK statement as
follows:
USING 'remote_database';
In this syntax:
● First, specify the name of the database link after the CREATE DATABASE LINK
keywords.
● Second, provide user and password of the remote database after the
CONNECT TO and IDENTIFIED BY keywords.
● Finally, specify the service name of the remote database. If you specify only
the database name, Oracle will append the database domain to the connect
string to form a complete service name.
Typically, you add an entry int the tnsnames.ora file and reference it as the
remote_database in the USING clause.
The following statement shows how to create the private database link to a user in a
remote database with a full connection string.
USING '(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=oracledb.example.com)
(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=service_name))
)';
USING 'remote_database';
USING 'remote_database';
First, add the following entry to tnsnames.ora file in the local Oracle Database server.
Typically, the tnsnames.ora is located in the directory /NETWORK/ADMIN/ under
ORACLE_HOME:
SALES =
(DESCRIPTION =
(SERVER = DEDICATED)
(SERVICE_NAME = SALES_PRD)
Next, use the CREATE DATABASE LINK statement to create a new private database
link that connects to the SALES database via bob‘s account:
USING 'SALES';
Then, issue the SELECT statement to query data from the customers table on the
SALES database: