当前位置:网站首页>Synchronization of data create trigger synchronization table for each site
Synchronization of data create trigger synchronization table for each site
2022-07-06 19:50:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
stay data Mention previous blogs when synchronizing , In every site there will be create triggers for every worksheet , When running CRUD. The task of trigger is to operate it sql The declaration is spliced into a string , And stored in the table synchro_tb_operate_log in , Suppose the trigger runs abnormally , Save its exception information in another table :SYNCHRO_DATA_EXCEP_LOG, among
synchro_tb_operate_log Field information : Primary key ID、 Spliced sql sentence ( Including the primary key ID And region code )、 Whether the synchronization is completed ( Tacit feeling 0 It's not over )、 Creation time
SYNCHRO_DATA_EXCEP_LOG Field information : Primary key ID、 Trigger exception name 、 Trigger exception information 、 The time when the trigger exception occurs
Here's how to create item_rec Code , Let's also learn the syntax and knowledge related to creating triggers :
create or replace
TRIGGER "ADMIN"."TRIGGER_ITEM_REC"
after insert or update or delete
on ITEM_REC FOR EACH ROW
/** HEAD
* @name Project log table trigger
* @description Change event . formation ddl Statement is inserted into the synchronization table
* @version 1.0.0
* @author Tang
* @create-date 2014-07-01
*/
declare
v_sql nvarchar2(3000); -- To store temporarily sql
v_zdcode varchar2(30):='08052'; -- Website code
v_exception varchar2(500);
begin
v_sql := null;
case when inserting then-- insert data
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-- Update data
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-- Delete data
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-- hypothesis v_sql Not empty . Then insert the corresponding information into synchro_tb_operate_log In the table
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-- Suppose an exception occurs during operation , Insert the exception information into SYNCHRO_DATA_EXCEP_LOG In the table
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;
Copyright notice : This article is an original blog article , Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117142.html Link to the original text :https://javaforall.cn
边栏推荐
- 350. Intersection of two arrays II
- 学习探索-使用伪元素清除浮动元素造成的高度坍塌
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
- [translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
- Phoenix Architecture 2 - accessing remote services
- 信息系统项目管理师---第八章 项目质量管理
- Hudi vs Delta vs Iceberg
- Configuration and simple usage of the EXE backdoor generation tool quasar
- AddressSanitizer 技术初体验
- AsyncHandler
猜你喜欢
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Spark foundation -scala
信息系统项目管理师---第八章 项目质量管理
Blue Bridge Cup microbial proliferation C language
腾讯Android面试必问,10年Android开发经验
Transformer model (pytorch code explanation)
Leetcode 30. 串联所有单词的子串
Mysql Information Schema 学习(一)--通用表
腾讯T3大牛手把手教你,大厂内部资料
随机推荐
LeetCode_双指针_中等_61. 旋转链表
js实现力扣71题简化路径
AddressSanitizer 技术初体验
LeetCode_ Double pointer_ Medium_ 61. rotating linked list
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
腾讯Android面试必问,10年Android开发经验
How to access localhost:8000 by mobile phone
Hudi vs Delta vs Iceberg
2022年6月语音合成(TTS)和语音识别(ASR)论文月报
POJ 3207 Ikki's Story IV – Panda's Trick (2-SAT)
Phoenix Architecture 2 - accessing remote services
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
Information System Project Manager - Chapter VIII project quality management
Zero foundation entry polardb-x: build a highly available system and link the big data screen
1805. 字符串中不同整数的数目
精彩编码 【进制转换】
手把手教你学会js的原型与原型链,猴子都能看懂的教程
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.