使用dblink同步本地数据库新增记录到远程服务器
2016-12-27 14:21
288 查看
参考
http://bbs.csdn.net/topics/330104541功能
用dblink、触发器实现两个数据库的同步。问题
在本地数据库中,有一张带clob字段的表,新增的记录无法同步到远程数据库。原因
触发器不可以直接访问远程数据库表中的clob字段。解决办法
在本地数据库中,创建一个结构相同的全局临时表。将新增的记录插入到临时表。
将临时表中的记录以insert into tableName@dblinkName select * from temp的形式插入到远程数据库。
示例
-- 创建全局临时表create global
temporary table temp
as select *from t_office_messages;
-- 创建触发器
create orreplace
trigger "T_OFFICE_MESSAGES_TRIGGER"
after
insert on T_OFFICE_MESSAGES --触发事件
for eachrow
-- 行级触发器
begin
if inserting
then
insert
into temp
(message_id,
msg_title,
accessory,
msg_send_per_id,
msg_send_per_name,
msg_send_date,
msg_is_enable,
msg_content,
msg_already_date,
msg_receivers,
msg_isold,
isdel,
isstarmark)
values
(:new.message_id,
:new.msg_title,
:new.accessory,
:new.msg_send_per_id,
:new.msg_send_per_name,
:new.msg_send_date,
:new.msg_is_enable,
:new.msg_content,
:new.msg_already_date,
:new.msg_receivers,
:new.msg_isold,
:new.isdel,
:new.isstarmark);
insert
into dzzw.t_office_messages@dzzwdblink
select
* from temp where message_id=
:new.message_id;
end if;
end;
相关文章推荐
- 使用phpstorm将本地代码实时自动同步到远程服务器
- Rsync使用非ssh默认端口从远程服务器同步文件到本地
- 从远程服务器数据库中同步数据到本地数据库 sql server 2008 开启分布
- Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库 自定义日志记录功能,按日记录,很方便 C#常量和字段以及各种方法的语法总结 类型,对象,线程栈,托管堆在运行时的关系,以及clr如何调用静态方法,实例方法,和虚方法 asp.net webapi 自定义身份验证
- 本地文件同步在远程服务器上使用
- 从远程服务器数据库中同步数据到本地数据库 sql server 2008 开启分布式事务
- 使用rsync同步镜像服务器数据,安装记录
- 使用rsync同步镜像服务器数据,安装记录
- 如何把本地数据库还原到远程服务器的数据库
- 10、使用rsync同步镜像服务器数据,安装记录
- 双服务器同步方案及实施办法,用最低成本实现灾难恢复,数据库远程备份
- Oracle 快照及 dblink使用 (两台服务器数据同步)
- Oracle 快照及 dblink使用 (两台服务器数据同步)
- ubuntu下如何使用sshfs加载远程服务器目录到本地文件系统
- 使用 Dropbox 实现服务器和本地资源的自动化同步
- 怎么把服务器的数据同步到本地数据库
- 使用cwRsync服务器文件夹同步备份操作记录
- 用svn和Rsync和php做本地开发环境、测试服务器、远程服务器同步和更新
- sqlserver2005 远程服务器数据 完全拷贝 到本地数据库
- ORACLE 存储过程 使用DBLINK 连接远程数据库