当前位置:网站首页>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
边栏推荐
- POJ3617 Best Cow Line 馋
- Tensorflow2.0 self defined training method to solve function coefficients
- 利用 clip-path 绘制不规则的图形
- Configuration and simple usage of the EXE backdoor generation tool quasar
- Application of clock wheel in RPC
- ZABBIX proxy server and ZABBIX SNMP monitoring
- Web开发小妙招:巧用ThreadLocal规避层层传值
- [play with Linux] [docker] MySQL installation and configuration
- Selenium advanced operations
- 腾讯T3手把手教你,真的太香了
猜你喜欢
Interview assault 63: how to remove duplication in MySQL?
【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
Configuration and simple usage of the EXE backdoor generation tool quasar
Mysql Information Schema 學習(一)--通用錶
面试突击63:MySQL 中如何去重?
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
LeetCode_ Double pointer_ Medium_ 61. rotating linked list
Interpretation of Dagan paper
Druid database connection pool details
思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
随机推荐
js实现力扣71题简化路径
121. 买卖股票的最佳时机
信息系统项目管理师---第八章 项目质量管理
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
学习探索-使用伪元素清除浮动元素造成的高度坍塌
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
String长度限制?
MySQL information schema learning (II) -- InnoDB table
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
Selenium advanced operations
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
Configuration and simple usage of the EXE backdoor generation tool quasar
MySql必知必会学习
激进技术派 vs 项目保守派的微服务架构之争
Interpretation of Dagan paper
技术分享 | 抓包分析 TCP 协议
Analysis of rainwater connection
Hudi vs Delta vs Iceberg
广州首个数据安全峰会将在白云区开幕