Oracle DBLINK creation and use

       When we need to cross the local database and access the data of the remote database, Oracle provides the dblink method, so that we can easily access the remote database as convenient as the local, let's take a look at the method of creating dblink.

 

Step 1: First check whether the current user has the permission to create dblink, if not, it needs to be authorized

select * from user_sys_privs t where t.privilege like upper('%link%'); command query, you can see from the result that the current user has create permission

CREATE DATABASE LINK--The dblink created can only be used by the creator, and cannot be used by other users

CREATE PUBLIC DATABASE LINK--public means that the created dblink can be used by all users

Granting needs to execute grant create public database link, create database link to myAccount under sys;

Step 2: Use the following sql to create

create database  link HSDblink1 connect to SBD_CXTJ identified by huawei123 using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.101.5)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = search)))';

TestDblink: Indicates the name of dblink

dbName: indicates the user of the remote database

dbPassword: indicates the password of the remote database

HOST: Indicates the remote database IP

PORT: Indicates the remote database port

SERVICE_NAME: the instance name of the remote database

Step 3: The SERVICE_NAME of the remote database can be queried under the sys user of the remote database

select name,value from v$parameter where name='service_names'

Step 4: Use dblink to access the remote database, the query is the same as the local

select * from teacher@HSDBLINK1;---teacher is the table name, HSDBLINK1 is the created dblink name

 

 

 

 

 

Guess you like

Origin blog.csdn.net/chudelong1/article/details/103408865