ORACLE

Oracle Create Database Link

intro

In Oracle, a database link is a pathway that enables the transfer of data between two separate databases. This allows users to access remote data as if it were stored locally, making it a valuable tool for organizations that need to centralize their data management and share information between different systems and departments.

Tools used in the tutorial
Tool Description Link
Dbvisualizer DBVISUALIZER
TOP RATED DATABASE MANAGEMENT TOOL AND SQL CLIENT
ORACLE logo thetable ORACLE
THE ORACLE DATABASE

DbVisualizer is a user-friendly database management software with a graphical interface for working with databases, including Oracle. One of its many capabilities is the ability to create and manage database links, making it an efficient and convenient tool for performing operations that make use of this pathway.

This article will guide you through the process of creating a database link in Oracle using DbVisualizer, including important tips and tricks to help you avoid common issues and make the most of this powerful tool.

In Oracle, a database link is a connection that allows users to access data from a remote database as if it were stored locally. It acts as a bridge between two databases and eliminates the need for copying data to multiple locations. All database links are identified by a unique name and can be accessed by prefixing the table name with the link name. They simplify data management by allowing centralized access to remote data and sharing information between different systems and departments.

Database links play a crucial role in modern organizations for several reasons:

  • Central Data Control: By connecting different databases, database links allow for central data management, ensuring its accuracy and consistency.
  • Information Exchange: Database links make it possible to share information between different systems and departments without having to copy data to multiple locations physically.
  • Streamlined Operations: By allowing users to access remote data as if it were stored locally, database links simplify data management and enhance operational efficiency.
  • Better Collaboration: Database links facilitate collaboration by enabling real-time information sharing between different systems and departments.
  • Scalable Solution: Database links provide a scalable solution for organizations that need to manage and access large amounts of data stored in multiple locations.

In Oracle, there are two types of database links: private and public.

Private links are created for a specific user or schema and can only be accessed by that user or schema. It is established using the CREATE PRIVATE DATABASE LINK command.

Public links are accessible to all users and schemas in the local database and can be used by anyone with the necessary privileges.

The choice between private and public links depends on the level of security and accessibility required for remote data. It is set up using the CREATE PUBLIC DATABASE LINK statement.

Creating a database link in Oracle using DbVisualizer is a simple and straightforward process. By following a step-by-step guide, you can easily establish a connection between two separate databases, allowing you to access remote data as if it were stored in your local database.

1. Installation of Oracle Database

First, we need to download the Oracle database on our local machine from the Oracle website.

Open the installation.Open the installation.
Open the installation.

After downloading, open the installation and set the username and password for the database.

Set the username and password for the database.
Set the username and password for the database.

The installation has been completed successfully.

The installation has been completed successfully.
The installation has been completed successfully.

2. Installation of DbVisualizer and JDK 17

As a prerequisite, download JDK 17 from the Oracle platform for DbVisualizer. Make sure to install JDK after carefully choosing your OS version.

Install JDK after carefully choosing your OS version.
Install JDK after carefully choosing your OS version.

After downloading JDK, install and verify it using the following command in CLI.

Copy
        
$ java --version
Install and verify the version using the following command in CLI.
Install and verify the version using the following command in CLI.

Now go to the following link and download DbVisualizer.

Download DbVisualizer.
Download DbVisualizer.

After downloading, open the installation and install DbVisualizer. Select whether you want to associate .sql file types with DbVisualizer making them open in the tool here:

Select whether you want to associate .sql file types with DbVisualizer.
Select whether you want to associate .sql file types with DbVisualizer.

Click Next, and you will see that DbVisualizer has been successfully installed.

DbVisualizer has been successfully installed.
DbVisualizer has been successfully installed.

3. Creating a Connection with Oracle through DbVisualizer

Now we will create a new connection with the Oracle database using DbVisualizer. Click on the highlighted plus icon and select the “Oracle 9i” option.

Create a new connection with the Oracle database using DbVisualizer.
Create a new connection with the Oracle database using DbVisualizer.

Now enter the username as “SYS” and Oracle DB password, choose the SYS Role as “SYSDBA,” and then click on the “Connect” button.

Enter the username as “SYS” and Oracle DB password and connect.
Enter the username as “SYS” and Oracle DB password and connect.

Now the connection has been established.

The connection has been established.
The connection has been established.

4. Get Pluggable Database and Set Container

To experience the behavior of database links in Oracle, we have to do some prerequisites, so get the name of our pluggable database by the following query.

Copy
        
1 SELECT PDB_NAME FROM DBA_PDBS;
ORCLPDB is the name of our pluggable database.
"ORCLPDB" is the name of our pluggable database.

ORCLPDB is the name of our pluggable database. Use it according to your settings by using the above query. Now use the alter session command and set the container with a pluggable database name.

Copy
        
1 ALTER SESSION SET CONTAINER = ORCLPDB;
Pluggable database has been set.
Pluggable database has been set.

Pluggable database has been set.

5. Create Users and Grant Access in the Current Container

Here, we will create 2 users that will display the behavior of 2 databases by which we can visualize the database link usage.

  • Create “User 1” and Grant Access. Run the following query to create “user 1” in the current container.
Copy
        
1 CREATE USER user1 IDENTIFIED BY user1_password DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON users CONTAINER = CURRENT;
Create “User 1” and Grant Access.
Create “User 1” and Grant Access.

Now grant necessary privileges to “user 1”.

Copy
        
1 GRANT CONNECT, RESOURCE, DBA TO user1;
Grant necessary privileges to “user 1”.
Grant necessary privileges to “user 1”.
  • Create “User 2” and Grant Access. Run the following query to create “user 2” in the current container.
Copy
        
1 CREATE USER user2 IDENTIFIED BY user2_password DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON users CONTAINER = CURRENT;
Create “User 2” and Grant Access.
Create “User 2” and Grant Access.

Now grant necessary privileges to “user 2”.

Copy
        
1 GRANT CONNECT, RESOURCE, DBA TO user2;
Grant necessary privileges to “user 2”.
Grant necessary privileges to “user 2”.

Great! You’ve now created users and granted some of the privileges to these users. Now it’s time to create a database link.

Now connect to “user 1” using DbVisualizer, and create a database link to “user 2”.

Copy
        
1 CREATE DATABASE LINK link_to_user2 2 CONNECT TO user2 IDENTIFIED BY user2_password 3 USING 'localhost:1521/ORCLPDB';
Connect to “user 1” and create a database link to “user 2”.
Connect to “user 1” and create a database link to “user 2”.

7. Create Database Tables and Insert Data

Create a table that will be associated with the first user (user1) and add one data row to it.

Copy
        
1 CREATE TABLE user1_table (id NUMBER, name VARCHAR2(100)); 2 INSERT INTO user1_table VALUES (1, 'John Doe');
Create a database table.
Create a database table.

Now create a table that will be associated with the second user (user2) and add one data row to it.

Copy
        
1 CREATE TABLE user2_table (id NUMBER, name VARCHAR2(100)); 2 INSERT INTO user2_table VALUES (1, 'Jane Smith');
Create a table that will be associated with the user 2.
Create a table that will be associated with the user 2.

After integrating and setting the Oracle database link, run the following query to test everything.

Copy
        
1 SELECT * FROM user2_table@link_to_user2;
Run the following query.
Run the following query.

Finally the user has access to the data from another database using the database link functionality.

Conclusion

In this article, we delved into the process of creating a database link in Oracle using DbVisualizer. We emphasized the significance of database links for centralizing data management and enabling information sharing between different systems and departments.

The steps involved in the process, prerequisites, and tips for troubleshooting common issues were also discussed. By using DbVisualizer, the process of creating a database link in Oracle becomes simpler and more efficient because of its abilities to run queries, simplify your workflow, and having specific features each of them designed to solve real-world problems. With a clear understanding of the steps involved and the troubleshooting tips provided, you can successfully create a database link in Oracle and take advantage of its benefits.

Visit our TheTable blog and stay tuned to learn more about the database world, and until next time.

Dbvis download link img
About the author
Igor Bobriakov
Igor Bobriakov
Igor is an entrepreneur and educator with a background in marketing and data science. His passion is to help small businesses and startups to utilize modern technology for growth and success. Igor is Data Scientist and ML Engineer. He founded Data Science School in 2016 and wrote numerous award-winning articles covering advanced tech and marketing topics. You can connect with him on LinkedIn or Twitter.
The Table Icon
Sign up to receive The Table's roundup
More from the table
Title Author Tags Length Published
title

SQL Upsert: Inserting a Record If It Does Not Exist

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2024-12-10
title

List of SQL Reserved Words in All Major Databases

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 16 min 2024-11-20
title

SQL Variable: What It Is and How To Use It

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2024-11-18
title

SQL Not Equal Operator: Definitive Guide with Examples

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 6 min 2024-10-14
title

SQL OFFSET: Skipping Rows in a Query

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 7 min 2024-09-30
title

SQL FETCH: Retrieving Data In Database Cursors

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2024-09-24
title

SQL Alias: Everything You Need to Know About AS in SQL

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 7 min 2024-07-15
title

How to Compare SQL Dates

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 4 min 2024-07-11
title

A Complete Guide to the SQL LIKE Operator

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 8 min 2024-06-17
title

A Guide to the SQL Date Data Types

author Antonello Zanini tags MySQL ORACLE POSTGRESQL SQL SQL SERVER 10 min 2024-05-30

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.

Cookie policy

We use cookies to ensure that we give you the best experience on our website. However you can change your cookie settings at any time in your browser settings. Please find our cookie policy here ↗