当前位置:网站首页>数据的同步为每个站点创建触发器同步表
数据的同步为每个站点创建触发器同步表
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
边栏推荐
- [play with Linux] [docker] MySQL installation and configuration
- 350. 两个数组的交集 II
- MySQL information Schema Learning (i) - - General table
- Dom 操作
- 《数字经济全景白皮书》保险数字化篇 重磅发布
- spark基础-scala
- [translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
- Documents to be used in IC design process
- Mysql Information Schema 學習(一)--通用錶
- Phoenix Architecture 2 - accessing remote services
猜你喜欢

After solving 2961 user feedback, I made such a change
![[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer](/img/8c/afb90128e7a523bbee4c6c4166363f.png)
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer

Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go

【计算情与思】扫地僧、打字员、信息恐慌与奥本海默

Microservice architecture debate between radical technologists vs Project conservatives

It's super detailed in history. It's too late for you to read this information if you want to find a job

Information System Project Manager - Chapter VIII project quality management

VMware virtual machine cannot open the kernel device "\.\global\vmx86"

Mysql Information Schema 學習(一)--通用錶

深入浅出,面试突击版
随机推荐
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
It's enough to read this article to analyze the principle in depth
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
凤凰架构2——访问远程服务
【pytorch】yolov5 训练自己的数据集
Interview assault 63: how to remove duplication in MySQL?
思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
Use of deg2rad and rad2deg functions in MATLAB
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
USB host driver - UVC swap
DaGAN论文解读
short i =1; I=i+1 and short i=1; Difference of i+=1
A popular explanation will help you get started
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
学习探索-无缝轮播图
Dom 操作
[play with Linux] [docker] MySQL installation and configuration
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发