Create and use Oracle DBLINK
How to create? How to use it?
Describes how to create and use Oracle database links.
A simple application scenario for Oracle DBLINK
If there are two Oracle databases, one day the business needs to make the data of one of the database tables compare and check with the data of another database table. This takes two steps:
Create DBLINK
Write related logic check SQL
Related code
- -- Create a public link
- CREATE PUBLIC DATABASE LINK TESTDBLINK
- Connect to remoteuser identified by REMOTEUSER_PW
- Using'(DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.0.1) (PORT = 1521 ))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = ORCL)
- )
- )';
- -- Test
- Select count (*) FROM PUBLIC_USER STD_L where not exists (
- SELECT 1 FROM PRIVATE_USER @ TESTDBLINK STD_R WHERE STD_R.USER_CODE = STD_L.USER_CODE
- )
- -- Kill Link
- DROP PUBLIC DATABASE LINK TESTDBLINK