oracle存储过程,增量同步处理数据、根据id新增或更新
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了oracle存储过程,增量同步处理数据、根据id新增或更新,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4040字,纯文字阅读大概需要6分钟。
内容图文
![oracle存储过程,增量同步处理数据、根据id新增或更新](/upload/InfoBanner/zyjiaocheng/447/e3ffeb978d6946fd8ba61e43d836550d.jpg)
同步处理的记录时间表:
CREATE TABLE jd_sync_handle( id varchar2(64) primary key, sync_time timestamp, handle_time timestamp ); comment on table jd_sync_handle is ‘数据处理表‘; comment on column jd_sync_handle.id is ‘主键,固定取值jd_unit、jd_unit_contract‘; comment on column jd_sync_handle.sync_time is ‘上次处理的表中最大同步时间‘; comment on column jd_sync_handle.handle_time is ‘上次处理的结束处理时间‘;
处理表初始化:
INSERT INTO JD_SYNC_HANDLE(ID, SYNC_TIME, HANDLE_TIME) VALUES (‘jd_unit‘, TO_TIMESTAMP(‘2020-11-20 16:12:43.000000‘, ‘SYYYY-MM-DD HH24:MI:SS:FF6‘), TO_TIMESTAMP(‘2020-11-20 16:12:50.000000‘, ‘SYYYY-MM-DD HH24:MI:SS:FF6‘));
增量同步处理数据、根据id新增或更新,存储过程:
CREATE OR REPLACE PROCEDURE jd_unit_handle AS -- 变量定义在begin在前 tmp_id jd_unit.id%TYPE; tmp_is_enable jd_unit.is_enable%TYPE; tmp_is_delete varchar2(1); tmp_create_time jd_unit.create_time%TYPE; tmp_update_time jd_unit.update_time%TYPE; tmp_unit_name jd_unit.unit_name%TYPE; tmp_unit_code jd_unit.unit_code%TYPE; tmp_sync_time jd_unit.sync_time%TYPE; handle_sync_time JD_SYNC_HANDLE.sync_time%TYPE; dbDataCnt int; CURSOR emp_cursor is select DISTINCT id,is_enable,case is_enable when ‘1‘ then ‘0‘ else ‘1‘ end,create_time,update_time,unit_name,unit_code,sync_time from jd_unit where sync_time>(select sync_time from JD_SYNC_HANDLE where id=‘jd_unit‘); BEGIN select sync_time into handle_sync_time from JD_SYNC_HANDLE where id=‘jd_unit‘; dbms_output.put_line(‘last handle_sync_time:‘||handle_sync_time); --循环开始 LOOP dbms_output.put_line(‘LOOP‘); IF NOT emp_cursor%ISOPEN THEN OPEN emp_cursor; END IF; FETCH emp_cursor INTO tmp_id,tmp_is_enable,tmp_is_delete,tmp_create_time,tmp_update_time,tmp_unit_name,tmp_unit_code,tmp_sync_time; dbms_output.put_line(‘FETCH-->id:‘||tmp_id); if tmp_id!=‘exit‘ then dbms_output.put_line(‘handle data‘); -- 处理同步时间:取查找的数据最大时间 if tmp_sync_time>handle_sync_time then handle_sync_time:=tmp_sync_time; dbms_output.put_line(‘handle_sync_time change:‘||handle_sync_time); else dbms_output.put_line(‘handle_sync_time no change‘); end if; -- 处理数据 -- 查询该id是否存在表中 select count(1) into dbDataCnt from yf_unit_type where id=tmp_id; dbms_output.put_line(‘dbDataCnt:‘||dbDataCnt); -- 判断是否存在该数据 if dbDataCnt=0 then insert into YF_UNIT_TYPE(ID,IS_ENABLE,IS_DELETE,CREATE_TIME,CREATE_USER_ID,UPDATE_TIME,UPDATE_USER_ID,UNIT_NAME,UNIT_CODE,UNIT_TYPE) values(tmp_id,tmp_is_enable,tmp_is_delete,tmp_create_time,‘1‘,tmp_update_time,‘1‘,tmp_unit_name,tmp_unit_code,‘a,b‘); else update YF_UNIT_TYPE set IS_DELETE=tmp_is_delete,IS_ENABLE=tmp_is_enable,CREATE_TIME=tmp_create_time,UPDATE_TIME=tmp_update_time,UNIT_NAME=tmp_unit_name,UNIT_CODE=tmp_unit_code where id=tmp_id; end if; -- 重置下是否存在表中 dbDataCnt:=0; else dbms_output.put_line(‘no data to handle‘); end if; --退出循环的条件 EXIT WHEN emp_cursor%NOTFOUND OR emp_cursor%NOTFOUND IS NULL; -- 退出设置id为值为exit tmp_id:=‘exit‘; END LOOP; dbms_output.put_line(‘END LOOP‘); -- 更新last handle_sync_time update JD_SYNC_HANDLE set sync_time=handle_sync_time,handle_time=sysdate where id=‘jd_unit‘; END;
oracle存储过程,增量同步处理数据、根据id新增或更新
标签:timestamp 创建时间 com hang 变量 mes weight 更新时间 sysdate
本文系统来源:https://www.cnblogs.com/xmqa/p/14046668.html
内容总结
以上是互联网集市为您收集整理的oracle存储过程,增量同步处理数据、根据id新增或更新全部内容,希望文章能够帮你解决oracle存储过程,增量同步处理数据、根据id新增或更新所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。