When a user wants to cross a local database, data access another database table, you must create a local database dblink remote database, you can access data in a remote database tables as access to local databases as through a local database dblink.
The following describes how to create dblink speaking in the local database.
The first step: to give permission
before creating the database link, we need to determine whether the logged in user has permission to create database link, so we execute the following statement:
- Check whether the user has permission to create a database link
select * from user_sys_privs where privilege like upper ( '% DATABASE LINK%') AND USERNAME = ' username';
If you have a query returns rows, then have the authority to create a database link, otherwise, you need to use landing sys orcl gives users permission to create:
- to grant users permissions to create dblink the
grant create public database link to a user name;
At this point, then execute sql statement above to see whether they have the authority, you will find the return line, said that the user has permission to create database link with the
second step; to create a database link
to create a way I've learned there are two: 1) graphical created by pl / sql developer, 2) created by sqlplus sql statement. The following describes the use of the sql statement to create a database link
Database Link TestDblink Create
Connect to dbName IDENTIFIED dbPassword by
the using '(= the DESCRIPTION (The ADDRESS_LIST = (ADDRESS = (the PROTOCOL = the TCP) (the HOST = 192.168.2.158) (PORT = 1521))) (the CONNECT_DATA = (SERVICE_NAME = ORCL))) ';
TestDblink: represents dblink name
dbName: means that the user remote database
dbPassword: represents the password for the remote database
HOST: indicates that the remote database IP
pORT: port represents the remote database
SERVICE_NAME: remote database instance name
- Query, delete and insert data and operating the local database is the same, just table names need to be written, "table name @dblink server" only.
For example: If you want to access a remote database via the local database dblink 'orcl' in dbName.tb_test table, sql statement is as follows
select * from dbName.tb_test@TestDblink;
DBLINK other related knowledge:
1, to see all the database link, log administrators to view
select owner,object_name from dba_objects where object_type='DATABASE LINK';
2. Delete the database connection
drop database link TestDblink;
Reference: https://www.cnblogs.com/wangyong/p/6354528.html , https://www.cnblogs.com/Animation-programmer/p/7991809.html