oracle database link instructions

Function: Treat multiple oracle databases as one database logically, that is to say, objects in another database can be manipulated in one database

Simple syntax:
CREATE [PUBLIC] DATABASE LINK dblink CONNECT TO user IDENTIFIED BY password USING 'connect_string'; 
DROP [PUBLIC] DATABASE LINK dblink; 
    Note: You must have the authority to CREATE DATABASE LINK or CREATE PUBLIC DATABASE LINK. On the connected database, you must have CREATE SESSION privilege.

Syntax explanation: 
    dblink: The connection name used in the sql statement later. In the init.ora file, if GLOBAL_NAMES=true, this dblink must be the same as the database global name (SELECT * FROM GLOBAL_NAME;). For convenience, you can ALTER SYSTEM SET GLOBAL_NAMES=FALSE; 
    user and password: the legal user name and password of the database to be connected 
    connect_string: can be an alias configured by Net Configuration Assistant (tnsnames.ora) and tested to connect, for example: orcl123, but it is prone to problems, Old prompt error: Unable to parse string. Better to write this form (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.78)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl ) ) )

使用: 
SELECT * FROM USER_TABLES@dblink
UPDATE jobs@dblink SET min_salary = 3000 WHERE job_id = 'SH_CLERK';


Links between databases are established on DATABASE LINK. To create a DB LINK, you must first set the link string on each database server. 
1. The link string is the service name. First, configure a service name locally, the address points to the remote database address, and the service name is the database chain name you want to use in the future:   
2. Create a database link and enter the system administrator SQL> operator , run the command: 
SQL>CREATE PUBLIC DATABASE LINK DBL_mesdb15 
CONNECT TO scott identified by tiger 
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.190.113.15)(PORT = 1521))
)
(CONNECT_DATA =
(service_name=mesdb)
)
)';

Then a link DBL_mesdb15 is created with the scott user and the MESDB database. We query the scott data of MESDB: 
SQL>select * from  emp@DBL_mesdb15
3. Create synonyms. In order to make the distributed operation more transparent, there are synonyms in the ORACLE database. Object synonym 
SQL>create synonym bjscottem for  emp@DBL_mesdb15
So bjscottem can be used to replace the distributed link operation emp@DBL_mesdb15 with @ symbol . 
4. View all database links, enter the system administrator SQL>operator, and run the command: 
SQL>select owner,object_name from dba_objects where object_type='DATABASE LINK'; 5.Check
the database connection
sql>select owner, db_link from dba_db_links ; 
power db_link
public TEST.US.ORACLE.COM

6. Delete the database connection
First, check the database connection from the third step, and obtain the name of its db_link
sql>drop public database link DBL_mesdb15.US.ORACLE.COM The
database connection has been discarded

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326189296&siteId=291194637