加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用dblink同步本地数据库新增记录到远程服务器

发布时间:2020-12-12 15:31:41 所属栏目:百科 来源:网络整理
导读:参考 http://bbs.csdn.net/topics/330104541 功能 用dblink、触发器实现两个数据库的同步。 问题 在本地数据库中,有一张带clob字段的表,新增的记录无法同步到远程数据库。 原因 触发器不可以直接访问远程数据库表中的clob字段。 解决办法 在本地数据库中,

参考

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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读