oracle 查找序列号,Oracle 查找丢失数据序列号

昨天数据中心一个人来找我,可能手贱删除一条数据,或者档案号存在但是权利人名称和土地证号缺失。

档案号存在但是权利人名称和土地证号丢失很简单 ,只要判断一下is null就可以获得档案号。

但是数据被删除了来找缺失的数据我研究了半天,多方百度终于解决。

1.首先把档案号字段拆分成数字

0818b9ca8b590ca3270a3433284dd417.png

select (replace(substr(c.DH,9,14),'-',''))

from (select * from T_ARCHIVE t where DH like 'J202-国土·1-2013%' and DH is not null) c

0818b9ca8b590ca3270a3433284dd417.png

2.  (重点!)使用oracle的connect by level 构造一个序列(所有档案号都存在)

select * from (

select ('12013001000' +Level) dtll from dual

connect by level <=

(select max(replace(substr(d.DH,9,14),'-','')) from (select * from T_ARCHIVE t where DH like 'J202-国土·1-2013%' and DH is not null) d)-'12013001000')

0818b9ca8b590ca3270a3433284dd417.png

3.只要判断 1步骤中的数据 not exists 2步骤的序列 就可以查找出丢失的档案号 (注意这里不能用not in ,我也不知道为什么 ,用了就会无限正在执行 QAQ)

select * from (

select ('12015001000' +Level) dtll from dual

connect by level <=

(select max(replace(substr(d.DH,9,14),'-','')) from (select * from T_ARCHIVE t where DH like 'J202-国土·1-2015%' and DH is not null) d)-'12015001000')

where not exists (select 1 from (select (replace(substr(c.DH,9,14),'-','')) tt

from (select * from T_ARCHIVE t where DH like 'J202-国土·1-2013%' and DH is not null) c ) s

where dtll=s.tt) order by dtll

省事我就没重新构造数据了,丢失的日期也同理可以获得。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值