dblink简单使用

1.配置tns

[oracle@pg1 admin]$ cat tnsnames.ora 
19c = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
    )
    (CONNECT_DATA = 
      (SERVICE_NAME = orcl)
    )
  )

11g = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
    )
    (CONNECT_DATA = 
      (SERVICE_NAME = prod)
    )
  )

ps:确定tns链接正常,好使

2.创建dblink

2.1模拟环境-1

1.在19c,pdb中创建用户
SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDB				          READ WRITE NO

SQL> alter session set container=pdb;
SQL> create user pdb_19c identified by oracle default tablespace users;
SQL> grant resource,connect to pdb_19c;



3.11g中创建19cpdb,pdb_19c用户的link-link_pdb
SQL> create database link link_pdb connect to pdb_19c identified by oracle using '19c';

4.在19c---pdb_19c用户中创建表
[oracle@pg1 admin]$ sqlplus pdb_19c/oracle@192.168.56.100:1521/pdb
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> create table a (id int);
SQL> insert into a (id) values (3);
insert into a (id) values (3)
            *
ERROR at line 1:
ORA-01950: no privileges on tablespace 'USERS'

解决:
oracle@pg1 admin]$ sqlplus sys/oracle@192.168.56.100:1521/pdb  as sysdba
SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 3 PDB				  READ WRITE NO

SQL> alter user pdb_19c quota unlimited on users;

[oracle@pg1 admin]$ sqlppdb_19c/oracle@192.168.56.100:1521/pdb

SQL>  insert into a (id) values (3);
SQL> commit;
Commit complete.

2.2 模拟环境-2

1. 11g中创建用户
SQL> grant connect,resource to test identified by oracle;

2.创建pdb相应的tns
pdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pdb)
    )
  )

2. 赋予test用户创建dblink的权限
SQL> grant create public database link to test;

4. 11g中链接test用户,并创建dblink---link_pdb
[oracle@pg1 admin]$ sqlplus test/oracle@11g
SQL> create public database link link_pdb connect to  pdb_19c identified by oracle using 'pdb';

5.验证dblink是否创建成功
SQL> select * from a@link_pdb;

	ID
----------
	 3

3. dblink查看

--以下操作都在sys用户中进行
---查看全部用户
SELECT OWNER,OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE= 'DATABASE LINK' ;

---查看全部用户
19c:
SQL> col owner for a20
SQL> col db_link for a20
SQL> col username for a10
SQL> col host for a15
SQL> set linesize 400
SQL> select * from dba_db_links;
OWNER		     DB_LINK		  USERNAME   HOST	     CREATED   HID SHA VAL INT
-------------------- -------------------- ---------- --------------- --------- --- --- --- ---
SYS		     SYS_HUB			     SEEDDATA	     17-APR-19 NO  NO  YES NO

11g:哪个用户创建的dblink哪个用户登录,sys登录可查看全部的dblink
SQL> col owner for a20
col db_link for a20
col username for a10
col host for a15
set linesize 400
select * from dba_db_links;

OWNER		     DB_LINK		  USERNAME   HOST	     CREATED
-------------------- -------------------- ---------- --------------- ---------
SYS		     LINK_PDB		  PDB_19C    19c	     04-AUG-23
PUBLIC		     LINK_PDB		  PDB_19C    pdb	     04-AUG-23
11g:
SQL> drop database link LINK_PDB;

SQL> col owner for a20
col db_link for a20
col username for a10
col host for a15
set linesize 400
select * from USER_DB_LINKS;

no rows selected
相关推荐
LKID体4 小时前
Python操作neo4j库py2neo使用(一)
python·oracle·neo4j
斗-匕5 小时前
Spring事务管理
数据库·spring·oracle
一行玩python5 小时前
SQLAlchemy,ORM的Python标杆!
开发语言·数据库·python·oracle
王ASC7 小时前
ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值。ojdbc8版本23.2.0.0驱动BUG【已解决】
数据库·sql·oracle
不爱学习的啊Biao8 小时前
初识mysql数据库
数据库·mysql·oracle
SRC_BLUE_178 小时前
SQLI LABS | Less-55 GET-Challenge-Union-14 Queries Allowed-Variation 2
oracle·c#·less
.11 小时前
接口 测试
数据库·oracle
LIT-涛14 小时前
JavaEE初学07
数据库·oracle·java-ee
奈斯ing16 小时前
【Oracle篇】SQL性能优化实战案例(从15秒优化到0.08秒)(第七篇,总共七篇)
运维·数据库·sql·oracle·性能优化
小小宇宙中微子16 小时前
mysql 命名约束
数据库·sql·oracle