ORACE 数据迁移 数据清洗 简单得统计配置

简介: 一份Oracle 数据清洗的统计程序

编写得目的:

   1 在数据迁移中,日常数据清洗是一个很频繁得工作。如果每次通过sql分步执行会非常麻烦及耗时。
        所以通过自动统计执行的方式处理减少不必要的重复并且简单的工作量
   2 在大量的任务及着急催促下 减少出错的概率
   3 所以统计信息同步数据库存储 从而 信息共享 方便工作使用 如 在家远程 等等的,同事协助处理,会简单并且
     方便很多

第一 我们创建一张RS_STATISTICS表 存储我们的统计信息及统计脚本
第二 根据我们的RS_STATISTICS 的内容 通过存储过程去 执行我们要统计的脚本

    在这里只需要使用到 动态执行 即可

/*
create table RS_STATISTICS
(
rs_id VARCHAR2(50),
rs_type VARCHAR2(50),
rs_name VARCHAR2(50),
rs_content VARCHAR2(4000),
rs_table VARCHAR2(50),
rs_num NUMBER,
op_tm DATE default sysdate not null,
rs_sts NUMBER default 0 not null,
ct DATE,
ut DATE,
memo VARCHAR2(3000),
rs_exception VARCHAR2(3000)
)
tablespace SYNCSH_DAT
pctfree 10
initrans 1
maxtrans 255
storage
(

initial 64K
next 1M
minextents 1
maxextents unlimited

);
-- Add comments to the columns
comment on column RS_STATISTICS.rs_id
is 'ID';
comment on column RS_STATISTICS.rs_type
is '类型';
comment on column RS_STATISTICS.rs_name
is '名称';
comment on column RS_STATISTICS.rs_content
is '内容';
comment on column RS_STATISTICS.rs_table
is '表';
comment on column RS_STATISTICS.rs_num
is '数量';
comment on column RS_STATISTICS.op_tm
is '录入时间';
comment on column RS_STATISTICS.ct
is '开始时间';
comment on column RS_STATISTICS.ut
is '更新时间';
comment on column RS_STATISTICS.memo
is '备注';
comment on column RS_STATISTICS.rs_sts
is '状态 0 待执行,1 执行中,2 执行成功,4 异常';

*/

create or replace package p_rs_statistics is

--// 程序启动
procedure p_start;
--// 初始化 数据存储表
procedure p_Complement;
--// 程序处理
procedure perform(p_id varchar2);
--// 清空落地表数据
procedure truncate_str(rs_table varchar2);
--// drop 表
procedure drop_str(rs_table varchar2);

end p_rs_statistics;
/
create or replace package body p_rs_statistics is

procedure p_start is
begin

for x in (select d.rs_id from syncsh.rs_statistics d where d.rs_sts = 0) loop
  update syncsh.rs_statistics d
     set d.rs_sts = 1, d.rs_exception = null, d.rs_num = 0,ct=sysdate
   where d.rs_id = x.rs_id;
  commit;
  perform(x.rs_id);
end loop;

exception

when others then
  rollback;

end;

procedure p_Complement is

v_rs_statistics syncsh.rs_statistics%rowtype;

begin

update syncsh.rs_statistics d
   set d.rs_table = 'syncsh.rs_statistics_' || d.rs_id
 where 1 = 1;
commit;

end;

procedure perform(p_id varchar2) is

v_rs_statistics syncsh.rs_statistics%rowtype;
exec_str        varchar2(4000);
p_sqlerrm       varchar2(4000);

begin

select *
  into v_rs_statistics
  from syncsh.rs_statistics d
 where d.rs_id = p_id;
---> 清空表
p_rs_statistics.truncate_str(v_rs_statistics.rs_table);
---> 删除表
p_rs_statistics.drop_str(v_rs_statistics.rs_table);
---> 创建 录入数据
exec_str := 'create table ' || v_rs_statistics.rs_table || ' as ' ||
            v_rs_statistics.rs_content;
execute immediate exec_str;
v_rs_statistics.rs_num := sql%rowcount;
dbms_output.put_line('rs_num :' || v_rs_statistics.rs_num);
--> 更新状态
update syncsh.rs_statistics d
   set d.rs_num = v_rs_statistics.rs_num, d.rs_sts = 2, d.ut = sysdate
 where d.rs_id = p_id;
commit;

exception

when others then
  p_sqlerrm := substr(sqlerrm, 1, 500);
  dbms_output.put_line('exec_str : ' || exec_str);
  dbms_output.put_line('ID :' || p_id || ' 异常 : ' || p_sqlerrm);
  --> 记录异常
  update syncsh.rs_statistics d
     set d.rs_exception = p_sqlerrm, d.rs_sts = 4, d.ut = sysdate
   where d.rs_id = p_id;
  commit;

end;

procedure truncate_str(rs_table varchar2) is

truncate_str varchar2(4000);
p_sqlerrm    varchar2(4000);

begin

truncate_str := 'truncate table  ' || rs_table;
execute immediate truncate_str;

exception

when others then
  p_sqlerrm := substr(sqlerrm, 1, 500);
  dbms_output.put_line('truncate rs_table :' || rs_table || ' 异常 : ' ||
                       p_sqlerrm);

end;

procedure drop_str(rs_table varchar2) is

drop_str  varchar2(4000);
p_sqlerrm varchar2(4000);

begin

drop_str := 'drop table  ' || rs_table;
execute immediate drop_str;
commit;

exception

when others then
  p_sqlerrm := substr(sqlerrm, 1, 500);
  dbms_output.put_line('drop rs_table :' || rs_table || ' 异常 : ' ||
                       p_sqlerrm);

end;

end p_rs_statistics;
/

/*
软件程序 脚本是为了提供方便而产生。愿可以减少不必要的时间浪费。
如 小伙伴提供一份 程序 导出execl 的最好了 感谢!
*/

目录
相关文章
|
SQL druid Java
搞懂JDBC这一篇就够了!!!(二)
搞懂JDBC这一篇就够了!!!(二)
283 0
搞懂JDBC这一篇就够了!!!(二)
|
小程序
小程序十大利剑,“割”新餐饮业
阿里云小程序运营干货分享
1404 0
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17716 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全
|
7天前
|
云安全 数据采集 人工智能
|
8天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1399 5
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2446 8
|
19天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3971 22

热门文章

最新文章