I will explain Create Database Link ( DBlink ) & Privilege in Oracle in this post.
Create Database Link ( DBlink ) in Oracle
Database link ( Dblink ) is used for connection between 2 different Oracle database. You can query any table from Remote database using DBLink in Oracle database.
To use dblink, you need to create database link in target database like following.
CREATE public DATABASE LINK PRODLINK CONNECT TO mehmet IDENTIFIED BY mehmet USING '192.168.63.34:1521/DEVECI';
You can query crm.customers table which is in ‘192.168.63.34:1521/DEVECI’ database like following.
select * from [email protected];
This Database link (Prodlink) will connect to ‘192.168.63.34:1521/DEVECI’ via mehmet user and query database objects from remote database ( ‘192.168.63.34:1521/DEVECI’ ).
You can create database links both Public and Private. When you create database link as private, then just related user can use it. If database link is created as public, then everyone can use it.
You can create private dblink with TNS like following.
CREATE DATABASE LINK DB_LINK CONNECT TO mehmet IDENTIFIED BY mehmet USING '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (HOST=192.168.63.34)(PORT=1521))) (CONNECT_DATA=(SERVER = DEDICATED)(SID = DEVECI)) )';
Create Database Link Privilege in Oracle
If you want to give Create Database Link Privilige to any user, you can do it as follows.
grant CREATE DATABASE LINK to username; SQL> grant CREATE DATABASE LINK to mehmet; Grant succeeded. SQL>
You can also use “select insert” using dblink like following from remote database to source database.
insert into crm.customers select * from [email protected] where createdat>sysdate-3; commit;
You can query count of crm.customers table which is in the like following.
select count(*) from [email protected]_LINK;
Drop Database Link
You can drop any database link as follows.
drop DATABASE LINK dblink_name; SQL> drop DATABASE LINK READ_LINK;
Do you want to learn Oracle Database for Beginners, then read the following articles.
1,353 views last month, 1 views today