当前位置:网站首页>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
边栏推荐
- Method keywords deprecated, externalprocname, final, forcegenerate
- beegfs高可用模式探讨
- String长度限制?
- 腾讯T3手把手教你,真的太香了
- Learning and Exploration - function anti shake
- Druid database connection pool details
- 终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
- Introduction to enterprise lean management system
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Using clip path to draw irregular graphics
猜你喜欢
JDBC details
beegfs高可用模式探讨
Using clip path to draw irregular graphics
Leetcode 30. Concatenate substrings of all words
Hudi vs Delta vs Iceberg
DaGAN论文解读
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
Example of applying fonts to flutter
Low CPU load and high loadavg processing method
随机推荐
腾讯T3手把手教你,真的太香了
Application of clock wheel in RPC
redisson bug分析
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
LeetCode_双指针_中等_61. 旋转链表
Mysql Information Schema 学习(一)--通用表
RT-Thread 组件 FinSH 使用时遇到的问题
Web开发小妙招:巧用ThreadLocal规避层层传值
POJ 3207 Ikki's Story IV – Panda's Trick (2-SAT)
某东短信登录复活 安装部署教程
凤凰架构3——事务处理
How to do smoke test
AddressSanitizer 技术初体验
Dom 操作
学习探索-函数防抖
Mysql Information Schema 学习(二)--Innodb表
golang的超时处理使用技巧
转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
广州首个数据安全峰会将在白云区开幕