当前位置:网站首页>Oracle DatabaseLink cross database connection

Oracle DatabaseLink cross database connection

2022-06-11 12:27:00 Three years old, funny

Oracle DatabaseLink Cross database operations

I have such a need in my daily work , To build a test environment , You need to import some tables and data from the development library into the test library . Or use some tables in the development library in the test library , The data of the view . At first glance, there are many implementation methods for this requirement , At least... Can be used Oracle Import and export of . This can certainly be achieved , But the feeling is quite low, Let's take a look at a tall and fashionable way , Use Oracle Medium DATABASE LINK.

DATABASE LINK seeing the name of a thing one thinks of its function , Is the connection to the database , The function is to connect to other databases , And convenient operation of other data . But from this point of view , Is it very powerful .DATABASE LINK There are two kinds of , One is public , One is private , Here we mainly introduce the public .

1. establish DATABASE LINK ( Remote connection Library )

create public database link DATABASE_LINK_NAME
  connect to CONNECT_DATABASE_USER identified by "CONNECT_DATABASE_PASSWORD"
  using '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = CONNECT_ORACLE_SERVER)(PORT = CONNECT_ORACLE_SERVER_PORT))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = CONNECT_ORACLE_SERVICE_NAME)
    )
  )';

For example, I want to connect 192.168.101.111 Under this server The port number is 1521 Of orcl Database instance . User name is scott The password is tiger,database link The name is scottdl

create public database link scottdl
  connect to scott identified by "tiger"
  using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.101.111)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )';

This creates a DATABASE LINK

-- see link
select * from dba_db_links;
 Delete DATABASE LINK
drop public database link scottdl;

2. Use DATABASE LINK

I want to put emp The data table , Sync to my database , You can do that

create table test as (select * from EMP @scottdl );

Direct query is also possible

select * from EMP @scottdl(link name )

newly build DATABASE LINK Option two

1. open PL/SQL Tool NEW
 Insert picture description here

  1. Fill in the configuration information
     Insert picture description here
  2. After creation, you can view it in the folder or sql Inquire about
-- see link
select * from dba_db_links;

Finally, you can do what you want , Isn't that easy !

原网站

版权声明
本文为[Three years old, funny]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111209201159.html