oracle 10g
数据清洗的要求,要找出一些合法数据.
有test表,字段crotime的数据如下,
123445
abcd
1-02-02
2008-01-01
2008-3-23
08-4-2
02-02现在我想找出下面这样的数据:
2008-01-01
2008-3-23
08-4-2请问应该如写SQL??多谢各位了...在线等.!

解决方案 »

  1.   

    select * from test where instr(crotime,'-')>0
      

  2.   

    -- 10g可以用正则
    SQL> select crotime from test;CROTIME
    ----------
    123445
    abcd
    1-02-02
    2008-01-01
    2008-3-23
    08-4-2
    02-027 rows selectedSQL>  select * from test a where REGEXP_LIKE(a.crotime,'^\d{2,4}-\d{1,2}-\d{1,2}$');CROTIME
    ----------
    2008-01-01
    2008-3-23
    08-4-2SQL> 
      

  3.   

    如果只是求关于时间的数据是否正确,可以写一个自定义函数:用to_date函数去转换字符串数据为时间数据,如果没报错就是合法数据;如果报错了就是非法数据。
      

  4.   

    3楼确实厉害..方法不错..修改下我上面发的方法,
    select * from test where instr(crotime,'-',1,2)>0大伙提供了几种方法,lz自己选合适的哦。
      

  5.   

    最好还是用function去写吧,像mantisXF所说.我的写法只对你本列数据合适.