当前位置:网站首页>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
边栏推荐
- Standardized QCI characteristics
- Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
- Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
- [玩转Linux] [Docker] MySQL安装和配置
- 【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
- Phoenix Architecture 2 - accessing remote services
- 潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
- 凤凰架构3——事务处理
- [infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
- Leetcode 30. Concatenate substrings of all words
猜你喜欢
![[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.](/img/09/106adc222c06cbd2f4f66cf475cce2.jpg)
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.

深入浅出,面试突击版

Li Kou 101: symmetric binary tree

Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand

Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference

面试突击63:MySQL 中如何去重?

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

Interview assault 63: how to remove duplication in MySQL?
![[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system](/img/63/3addcecb69dcb769c4736653952f66.png)
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system

Analysis of rainwater connection
随机推荐
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
After solving 2961 user feedback, I made such a change
redisson bug分析
凤凰架构2——访问远程服务
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
Web开发小妙招:巧用ThreadLocal规避层层传值
mod_wsgi + pymssql通路SQL Server座
Zero foundation entry polardb-x: build a highly available system and link the big data screen
Yyds dry goods inventory leetcode question set 751 - 760
POJ1149 PIGS 【最大流量】
技术分享 | 抓包分析 TCP 协议
部门树递归实现
信息系统项目管理师---第八章 项目质量管理
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
小微企业难做账?智能代账小工具快用起来
句号压缩过滤器
【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
腾讯云数据库公有云市场稳居TOP 2!