找出不规范的日期数据

<pre name="code" class="sql"><pre name="code" class="sql">create table test10 (set_date varchar2(10));

SQL> desc test10
 名称					   是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 SET_DATE					    VARCHAR2(10)


SQL> select set_date,count(*) from test10
  2  group by set_date
  3  order by count(*);

SET_DATE     COUNT(*)
---------- ----------
2012/08/47	    1
20111259	    1
2012/09/91	    1
2013-08-37	    1
2014-05-07	16384
2013-01-01	16384
2012/10/10	16384
20100809	16384
20110919	16384

已选择9行。

select a.set_date,to_date(set_date,'YYYY-MM-DD') from test10 a;
2013-01-01 01-1月 -13
20110919   19-9月 -11

SET_DATE   TO_DATE(SET_DA
---------- --------------
2014-05-07 07-5月 -14
20100809   09-8月 -10
2012/10/10 10-10月-12
2013-01-01 01-1月 -13
20110919   19-9月 -11
2014-05-07 07-5月 -14
20100809   09-8月 -10
2012/10/10 10-10月-12
2013-01-01 01-1月 -13
20110919   19-9月 -11
ERROR:
ORA-01847: 月份中日的值必须介于 1 和当月最后一日之间


怎么找出不符合日期的天数呢?

SQL> select a.set_date,substr(set_date,9,2) from test10 a
where length(set_date)=10
and substr(set_date,9,2)>31
union
select a.set_date,substr(set_date,7,2) from test10 a 
where 
length(set_date)=8
and substr(set_date,7,2)>31
  2    3    4    5    6    7    8    9  ;

SET_DATE   SUBS
---------- ----
20111259   59
2012/08/47 47
2012/09/91 91
2013-08-37 37

或者 
select a.set_date,substr(set_date,7,2) from test10 a
where substr(set_date,7,2) not like '%//%' escape '/'
and substr(set_date,7,2) not like '%--%' escape '-'
and substr(set_date,7,2)>31
union
select a.set_date,substr(set_date,9,2) from test10 a
where substr(set_date,9,2)>31


 
 
 
 
 

转载于:https://www.cnblogs.com/zhaoyangjian724/p/3797849.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值