当前位置:网站首页>数据的同步为每个站点创建触发器同步表
数据的同步为每个站点创建触发器同步表
2022-07-06 11:47:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
在数据同步时提到以前的博客,在每个站点都会有创建触发器对于每个工作表,当运行CRUD。触发器的任务就是对其进行操作sql声明拼接成一个字符串,并存储在表中synchro_tb_operate_log中,假设触发器运行出现异常,则将其异常信息保存在还有一个表中:SYNCHRO_DATA_EXCEP_LOG,当中
synchro_tb_operate_log字段信息:主键ID、拼接的sql语句(当中包括主键ID和地区代码)、是否完毕同步(默觉得0未完毕)、创建时间
SYNCHRO_DATA_EXCEP_LOG字段信息:主键ID、触发器异常名称、触发器异常信息、触发器异常出现的时间
以下是创建item_rec代码,也能够让我们来学习一下创建触发器相关的语法和知识:
create or replace
TRIGGER "ADMIN"."TRIGGER_ITEM_REC"
after insert or update or delete
on ITEM_REC FOR EACH ROW
/** HEAD
* @name 项目记录表触发器
* @description 变更事件。形成ddl语句插入同步表中
* @version 1.0.0
* @author Tang
* @create-date 2014-07-01
*/
declare
v_sql nvarchar2(3000); --暂时存放sql
v_zdcode varchar2(30):='08052'; --网站代码
v_exception varchar2(500);
begin
v_sql := null;
case when inserting then--插入数据
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--更新数据
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--删除数据
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--假设v_sql不为空。则将对应信息插入到synchro_tb_operate_log表中
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--假设运行过程中出现异常,则将异常信息插入到SYNCHRO_DATA_EXCEP_LOG表中
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;
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117142.html原文链接:https://javaforall.cn
边栏推荐
- A popular explanation will help you get started
- [translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
- spark基础-scala
- Druid database connection pool details
- [infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
- Blue Bridge Cup microbial proliferation C language
- zabbix 代理服务器 与 zabbix-snmp 监控
- JDBC详解
- Alibaba data source Druid visual monitoring configuration
- Translation D28 (with AC code POJ 26:the nearest number)
猜你喜欢
PMP practice once a day | don't get lost in the exam -7.6
Druid database connection pool details
Application of clock wheel in RPC
Interview assault 63: how to remove duplication in MySQL?
It's enough to read this article to analyze the principle in depth
Interpretation of Dagan paper
spark基础-scala
Druid 数据库连接池 详解
MySQL information schema learning (II) -- InnoDB table
JDBC details
随机推荐
蓝桥杯 微生物增殖 C语言
ZABBIX proxy server and ZABBIX SNMP monitoring
MySQL information schema learning (I) -- general table
Test Li hi
Recursive implementation of department tree
js实现力扣71题简化路径
An error occurs when installing MySQL: could not create or access the registry key needed for the
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
Interview assault 63: how to remove duplication in MySQL?
学习探索-使用伪元素清除浮动元素造成的高度坍塌
Tencent Android interview must ask, 10 years of Android development experience
Black Horse - - Redis Chapter
Blue Bridge Cup microbial proliferation C language
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
[play with Linux] [docker] MySQL installation and configuration
PMP practice once a day | don't get lost in the exam -7.6
【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
从sparse.csc.csr_matrix生成邻接矩阵
保证接口数据安全的10种方案
GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions