如何实现两个数据库的同步
1个回答
展开全部
sql同步使用dblink同步数据。
具体参考实例:
1、在win下创建linux的DBLINK
a.查看linux下的tnsnames.ora文件
[oracle@myrac1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /s01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
HJJ =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myrac1.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hjj)
)
)
b.创建dblink
SQL> create database link win_lin_link connect to hjj identified by xxxx
2 using '(DESCRIPTION =
3 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.171)(PORT = 1521))
4 (CONNECT_DATA =
5 (SERVER = DEDICATED)
6 (SERVICE_NAME = hjj)
7 )
8 )'
9 /
Database link created.
2.在win下创建trigger
SQL> create or replace trigger trig_win_emp
2 after insert on emp
3 for each row
4 begin
5 insert into emp@win_lin_link values(:new.empno,:new.empname,:new.empsalary);
6 end;
7 /
Trigger created.
3.测试
4.结果
win下插入数据
SQL> insert into emp values('E001','LYN',2300);
1 row created.
SQL>COMMIT;
Commit complete.
SQL> select *from emp;
EMPNO EMPNAME EMPSALARY
---------------------------------------- ---------------------------------------- ----------
E001 LYN 2300
SQL> select * from emp@win_lin_link;
EMPNO EMPNAME EMPSALARY
---------------------------------------- ---------------------------------------- ----------
E001 LYN 2300
linux下查看数据
SQL> select * from emp;
EMPNO EMPNAME EMPSALARY
-------------------- -------------------- ----------
E001 LYN 2300
具体参考实例:
1、在win下创建linux的DBLINK
a.查看linux下的tnsnames.ora文件
[oracle@myrac1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /s01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
HJJ =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myrac1.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hjj)
)
)
b.创建dblink
SQL> create database link win_lin_link connect to hjj identified by xxxx
2 using '(DESCRIPTION =
3 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.171)(PORT = 1521))
4 (CONNECT_DATA =
5 (SERVER = DEDICATED)
6 (SERVICE_NAME = hjj)
7 )
8 )'
9 /
Database link created.
2.在win下创建trigger
SQL> create or replace trigger trig_win_emp
2 after insert on emp
3 for each row
4 begin
5 insert into emp@win_lin_link values(:new.empno,:new.empname,:new.empsalary);
6 end;
7 /
Trigger created.
3.测试
4.结果
win下插入数据
SQL> insert into emp values('E001','LYN',2300);
1 row created.
SQL>COMMIT;
Commit complete.
SQL> select *from emp;
EMPNO EMPNAME EMPSALARY
---------------------------------------- ---------------------------------------- ----------
E001 LYN 2300
SQL> select * from emp@win_lin_link;
EMPNO EMPNAME EMPSALARY
---------------------------------------- ---------------------------------------- ----------
E001 LYN 2300
linux下查看数据
SQL> select * from emp;
EMPNO EMPNAME EMPSALARY
-------------------- -------------------- ----------
E001 LYN 2300
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询