Oracle-dblink

1. Create a previous job

Before creating a dblink, first check whether the user has the appropriate permissions. For a specific user, after logging in using sqlplus user/pwd, execute the following statement:

Copy the code The code is as follows:
select * from user_sys_privs t where t.privilege like upper('%link%');


Under the sys user, the displayed result is:

 

SYS CREATE DATABASE LINK NO
SYS DROP PUBLIC DATABASE LINK NO
SYS CREATE PUBLIC DATABASE LINK NO

It can be seen that dblink has three permissions in the database:

CREATE DATABASE LINK--The created dblink can only be used by the creator, other users cannot use
CREATE PUBLIC DATABASE LINK--public means that all users of the created dblink can use
DROP PUBLIC DATABASE LINK--Delete the specified dblink

If you want to change the permissions of a user, you need to modify it under the sys user:

Copy the code The code is as follows:
grant CREATE PUBLIC DATABASE LINK,DROP PUBLIC DATABASE LINK to scott;


There are two ways to view dblink, as follows:

 

①.

Copy the code The code is as follows:
select owner,object_name from dba_objects where object_type='DATABASE LINK';


②.

Copy the code The code is as follows:
select * from dba_db_links;

 

2. Create dblink

?
1
2
3
4
5
6
create public database link LINK_NAME
connect to USRNAME identified by "PASSWORD"
using
'(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XXX.XXX)(PORT = 1521))
(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = XXX))
  )' ;

Note: using is followed by a string, in which there must be no unnecessary spaces, otherwise an error ORA-12514 will occur . In the above code, for the convenience of reading, a line break may appear, which may cause errors, so use It's ok to remove the spaces.

Here LINK_NAM is a custom name; USERNAME and PASSWORD are the user name and password in the specified oracle database, SERVICE_NAME can be obtained by the following statement if you are not sure:

Copy the code The code is as follows:
show parameter service_names;


or

Copy the code The code is as follows:
select name,value from v$parameter where name='service_names'


3. Use of dblink

 

The use of dblink is relatively simple. Change the table name when accessing a local table to the following format: [user.]table@link_name.

Copy the code The code is as follows:
select studentid from abc.studeng@abc_ten;


4. Delete dblink

 

After determining the name of the dblink to be deleted, you can delete it directly through the drop command:

Copy the code The code is as follows:
drop public database link abc_ten;

 

I hope that this article will be helpful to everyone in Oracle database programming.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326561883&siteId=291194637