Scenario simulation: The
currently logged-in library is ocrla, and my requirement is to query the data of the ocrlb library directly through SQL.
When Oracle performs cross-database access, it can be achieved by creating a dblink.
[Step 1: User permissions]
Check whether the current user has database link permissions
select * from user_sys_privs where privilege like upper('%DATABASE LINK%') AND USERNAME='ZHANGYU';
-- 如果user_sys_privs数据不多可以直接查找用户,注意这里用户名大写
If the query returns a row, it means that you have the permission to create a database link, otherwise, you need to use sys login to give the user creation permission
grant create public database link to zhangyu;
After the creation is complete, you can query user_sys_privs again
[Step 2: Create a database link] The
two methods can be created graphically by pl/sql developer, or created by SQL statements, here directly created by SQL
create database link LINKTEST
connect to zhangyu identified by "123456"
using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ocrla) ) )'
Note: If the password starts with a number, enclose it with ""
[Step 3: Verification] After the
creation is complete, you can query cross-database data in the following way:
table name@corresponding DataBase Link name
SELECT * FROM tableName@LINKTEST
After creation, you can also check
the deletion of DATABASE LINK through pl/sql developer
DROP PUBLIC DATABASE LINK link_name;