当前位置:网站首页>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
边栏推荐
- Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
- RT-Thread 组件 FinSH 使用时遇到的问题
- 句号压缩过滤器
- Interpretation of Dagan paper
- AsyncHandler
- After solving 2961 user feedback, I made such a change
- 腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
- DaGAN论文解读
- 理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
- (3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
猜你喜欢

【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)

DaGAN论文解读

【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
腾讯T2大牛亲自讲解,跳槽薪资翻倍

Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)

Transformer model (pytorch code explanation)

某东短信登录复活 安装部署教程

利用 clip-path 绘制不规则的图形

新一代垃圾回收器—ZGC

思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
随机推荐
Application of clock wheel in RPC
Interview assault 63: how to remove duplication in MySQL?
beegfs高可用模式探讨
In simple terms, interview surprise Edition
凤凰架构3——事务处理
Tensorflow2.0 自定义训练的方式求解函数系数
某东短信登录复活 安装部署教程
Standardized QCI characteristics
腾讯T3手把手教你,真的太香了
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
接雨水问题解析
Low CPU load and high loadavg processing method
Druid database connection pool details
蓝桥杯 微生物增殖 C语言
Selenium advanced operations
1805. 字符串中不同整数的数目
Learning and Exploration - Seamless rotation map
Social recruitment interview experience, 2022 latest Android high-frequency selected interview questions sharing
深入浅出,面试突击版
利用 clip-path 绘制不规则的图形