zoukankan      html  css  js  c++  java
  • 找出不规范的日期数据

    <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


    
    
    
    
    
    
    
    
  • 相关阅读:
    Elasticsearch之优化
    前端页面加载速度优化---Ngnix之GZIP压缩
    Nginx的try_files使用详解
    elk6.3.2在线安装中文分词工具IK
    filebeat5与filebeat6配置index的差异
    十分钟部署Anemometer作为Mysql慢查询可视化系统
    虚拟机磁盘逻辑卷扩容
    十分钟搭建和使用ELK日志分析系统
    关于NODEJS性能测试和优缺点总结
    十分钟搭建和使用sonarqube代码质量管理平台
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/3797849.html
Copyright © 2011-2022 走看看