当前位置:网站首页>数据的同步为每个站点创建触发器同步表
数据的同步为每个站点创建触发器同步表
2022-07-06 11:47:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
在数据同步时提到以前的博客,在每个站点都会有创建触发器对于每个工作表,当运行CRUD。触发器的任务就是对其进行操作sql声明拼接成一个字符串,并存储在表中synchro_tb_operate_log中,假设触发器运行出现异常,则将其异常信息保存在还有一个表中:SYNCHRO_DATA_EXCEP_LOG,当中
synchro_tb_operate_log字段信息:主键ID、拼接的sql语句(当中包括主键ID和地区代码)、是否完毕同步(默觉得0未完毕)、创建时间
SYNCHRO_DATA_EXCEP_LOG字段信息:主键ID、触发器异常名称、触发器异常信息、触发器异常出现的时间
以下是创建item_rec代码,也能够让我们来学习一下创建触发器相关的语法和知识:
create or replace
TRIGGER "ADMIN"."TRIGGER_ITEM_REC"
after insert or update or delete
on ITEM_REC FOR EACH ROW
/** HEAD
* @name 项目记录表触发器
* @description 变更事件。形成ddl语句插入同步表中
* @version 1.0.0
* @author Tang
* @create-date 2014-07-01
*/
declare
v_sql nvarchar2(3000); --暂时存放sql
v_zdcode varchar2(30):='08052'; --网站代码
v_exception varchar2(500);
begin
v_sql := null;
case when inserting then--插入数据
v_sql := 'insert into ITEM_REC('||
'ID,PROTEAMNAME,PY,PROID,'||
'JCTYPE,WORKFLAG,ZXFLAG,JWDCODE)'||
'values('''||
:new.ID||''','''||replace(:new.PROTEAMNAME,'''','')||''','''||:new.PY||''','''||:new.PROID||''','''||
:new.JCTYPE||''','''||:new.WORKFLAG||''','''||:new.ZXFLAG||''','''||v_jwdcode||''')';
when updating then--更新数据
v_sql := 'update ITEM_REC set '||
'PROTEAMNAME='''||replace(:new.PROTEAMNAME,'''','')||''''||
',PY='''||:new.PY||''''||
',PROID='''||:new.PROID||''''||
',JCTYPE='''||:new.JCTYPE||''''||
',WORKFLAG='''||:new.WORKFLAG||''''||
',ZXFLAG='''||:new.ZXFLAG||''''||
' where '||
'ID='||:old.ID||' and JWDCODE='''||v_jwdcode||'''';
when deleting then--删除数据
v_sql := 'delete from ITEM_REC t where t.ID='||:old.ID||' and t.JWDCODE='''||v_jwdcode||'''';
end case;
if v_sql is not null then--假设v_sql不为空。则将对应信息插入到synchro_tb_operate_log表中
insert into
synchro_tb_operate_log(sd_record_id,sd_record_sql,sd_flag,create_time)
values(SEQ_SYNCHRO_DATA.NEXTVAL,v_sql,0,to_char(sysdate,'YYYY-MM-DD HH24:MI:SS'));
end if;
exception
when others then--假设运行过程中出现异常,则将异常信息插入到SYNCHRO_DATA_EXCEP_LOG表中
v_exception := substr(sqlcode||'---'||sqlerrm, 1, 500);
insert into SYNCHRO_DATA_EXCEP_LOG
(ID,TRIGGER_NAME,EXCEPTION_INFO,EXCEPTION_TIME)
values
(sys_guid(),'Trigger_DICT_PROTEAM',v_exception,to_char(sysdate,'YYYY-MM-DD HH24:MI:SS'));
end TRIGGER_ITEM_REC;
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117142.html原文链接:https://javaforall.cn
边栏推荐
- 激进技术派 vs 项目保守派的微服务架构之争
- C # use Marshall to manually create unmanaged memory in the heap and use
- redisson bug分析
- MySQL information Schema Learning (i) - - General table
- Finally, there is no need to change a line of code! Shardingsphere native driver comes out
- Looting iii[post sequence traversal and backtracking + dynamic planning]
- 思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
- 颜色(color)转换为三刺激值(r/g/b)(干股)
- Unbalance balance (dynamic programming, DP)
- Druid 数据库连接池 详解
猜你喜欢
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
Using clip path to draw irregular graphics
MySQL information schema learning (I) -- general table
社招面试心得,2022最新Android高频精选面试题分享
Social recruitment interview experience, 2022 latest Android high-frequency selected interview questions sharing
思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
10 schemes to ensure interface data security
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
手把手教你学会js的原型与原型链,猴子都能看懂的教程
随机推荐
The slave i/o thread stops because master and slave have equal MySQL serv
Use of deg2rad and rad2deg functions in MATLAB
Test Li hi
Problems encountered in using RT thread component fish
About image reading and processing, etc
It's super detailed in history. It's too late for you to read this information if you want to find a job
In simple terms, interview surprise Edition
蓝桥杯 微生物增殖 C语言
[play with Linux] [docker] MySQL installation and configuration
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Cf960g - bandit Blues (type I Stirling number +ogf)
Social recruitment interview experience, 2022 latest Android high-frequency selected interview questions sharing
CPU负载很低,loadavg很高处理方法
It's enough to read this article to analyze the principle in depth
MySQL must know and learn
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
Hudi vs Delta vs Iceberg
反射及在运用过程中出现的IllegalAccessException异常
A5000 vGPU显示模式切换
关于图像的读取及处理等